From 13fe2bb05b06066191cd1234bf2cd0a22146582c Mon Sep 17 00:00:00 2001 From: OmniaX-Dev Date: Sun, 3 May 2026 22:13:38 +0200 Subject: [PATCH] Sync push --- extra/DefaultThemeDark.oss | 2 +- src/ostd/io/Stylesheet.cpp | 32 ++++++++++++++++++++++++++------ src/ostd/string/String.cpp | 19 ++++++++++++------- src/ostd/string/String.hpp | 4 ++-- 4 files changed, 41 insertions(+), 16 deletions(-) diff --git a/extra/DefaultThemeDark.oss b/extra/DefaultThemeDark.oss index 8e8aee6..915d91d 100644 --- a/extra/DefaultThemeDark.oss +++ b/extra/DefaultThemeDark.oss @@ -13,7 +13,7 @@ const $crimsonAccent = rgba(220, 20, 60, 150) % =================== -macro set_focus_border(color, test = "ciccio,ciao", width = 1, width2 = false) { +macro set_focus_border(color, test = "str", width = 1, width2 = false) { focusBorderColor = $color; showFocusBorder = $width2; focusBorderWidth = $width; diff --git a/src/ostd/io/Stylesheet.cpp b/src/ostd/io/Stylesheet.cpp index c0c17e1..22eb05a 100644 --- a/src/ostd/io/Stylesheet.cpp +++ b/src/ostd/io/Stylesheet.cpp @@ -931,9 +931,6 @@ namespace ostd macro.params.push_back({ "$" + tok, MacroParamDefault }); } } - // std::sort(macro.params.begin(), macro.params.end(), [](const auto& a, const auto& b) { - // return a.first.len() > b.first.len(); - // }); m_macros[name] = macro; return true; } @@ -970,23 +967,46 @@ namespace ostd callArgs.push_back(arg); return callArgs; }; + auto l_escapeRegex = [](const String& s) -> String { + ostd::String result = s; + result.replaceAll("\\", "\\\\"); + result.replaceAll(".", "\\."); + result.replaceAll("^", "\\^"); + result.replaceAll("$", "\\$"); + result.replaceAll("|", "\\|"); + result.replaceAll("(", "\\("); + result.replaceAll(")", "\\)"); + result.replaceAll("[", "\\["); + result.replaceAll("]", "\\]"); + result.replaceAll("{", "\\{"); + result.replaceAll("}", "\\}"); + result.replaceAll("*", "\\*"); + result.replaceAll("+", "\\+"); + result.replaceAll("?", "\\?"); + result.replaceAll("/", "\\/"); + return result; + }; auto callArgs = l_splitByTopLevelComma(call); auto tokens = macro.body.tokenize("\n"); for (auto& line : tokens) { i32 argIndex = 0; - for (const auto&[pname, pval] : macro.params) + for (const auto&[_pname, _pval] : macro.params) { + String pname = l_escapeRegex(_pname); + String pval = ""; if (argIndex < callArgs.size()) { - line.replaceAll(pname, callArgs[argIndex++]); + pval = callArgs[argIndex++].new_replaceAll("$", "$$"); + line.regexReplace(pname, pval); std::cout << pname << " " << callArgs[argIndex - 1] << "\n " << line << "\n"; continue; } if (pval == MacroParamDefault) return {}; - line.replaceAll(pname, pval); + pval = _pval.new_replaceAll("$", "$$"); + line.regexReplace(pname, pval); } std::cout << "\n"; lines.push_back(line); diff --git a/src/ostd/string/String.cpp b/src/ostd/string/String.cpp index 6d37454..901a87f 100644 --- a/src/ostd/string/String.cpp +++ b/src/ostd/string/String.cpp @@ -120,15 +120,20 @@ namespace ostd String& String::replaceAll(const String& what, const String& with) { - while (contains(what)) - replaceFirst(what, with); + if (what.len() == 0) return *this; + size_t pos = 0; + while ((pos = m_data.find(what.cpp_str(), pos)) != std::string::npos) + { + m_data.replace(pos, what.len(), with.cpp_str()); + pos += with.len(); + } return *this; } - String& String::replaceFirst(const String& what, const String& with) + String& String::replaceFirst(const String& what, const String& with, i32 startIndex) { - i32 index = indexOf(what); - if (index == -1) return *this; + i32 index = indexOf(what, startIndex); + if (index < 0) return *this; m_data.replace(index, what.len(), with.cpp_str()); return *this; } @@ -323,10 +328,10 @@ namespace ostd return __str.replaceAll(what, with); } - String String::new_replaceFirst(const String& what, const String& with) const + String String::new_replaceFirst(const String& what, const String& with, i32 startIndex) const { String __str = m_data; - return __str.replaceFirst(what, with); + return __str.replaceFirst(what, with, startIndex); } String String::new_regexReplace(const String& regex_pattern, const String& replace_with, bool case_insensitive) const diff --git a/src/ostd/string/String.hpp b/src/ostd/string/String.hpp index 17b6131..5397457 100644 --- a/src/ostd/string/String.hpp +++ b/src/ostd/string/String.hpp @@ -104,7 +104,7 @@ namespace ostd String& addRightPadding(u32 new_string_length, char c = ' '); String& reverse(void); String& replaceAll(const String& what, const String& with); - String& replaceFirst(const String& what, const String& with); + String& replaceFirst(const String& what, const String& with, i32 startIndex = 0); String& regexReplace(const String& regex_pattern, const String& replace_with, bool case_insensitive = false); String& put(u32 index, char c); String& substr(u32 start, i32 end = -1); @@ -134,7 +134,7 @@ namespace ostd String new_addRightPadding(u32 new_string_length, char c = ' ') const; String new_reverse(void) const; String new_replaceAll(const String& what, const String& with) const; - String new_replaceFirst(const String& what, const String& with) const; + String new_replaceFirst(const String& what, const String& with, i32 startIndex = 0) const; String new_regexReplace(const String& regex_pattern, const String& replace_with, bool case_insensitive = false) const; String new_put(u32 index, char c) const; String new_substr(u32 start, i32 end = -1) const;