Sync push

This commit is contained in:
OmniaX-Dev 2026-05-03 22:13:38 +02:00
parent fa638d2556
commit 13fe2bb05b
4 changed files with 41 additions and 16 deletions

View file

@ -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; focusBorderColor = $color;
showFocusBorder = $width2; showFocusBorder = $width2;
focusBorderWidth = $width; focusBorderWidth = $width;

View file

@ -931,9 +931,6 @@ namespace ostd
macro.params.push_back({ "$" + tok, MacroParamDefault }); 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; m_macros[name] = macro;
return true; return true;
} }
@ -970,23 +967,46 @@ namespace ostd
callArgs.push_back(arg); callArgs.push_back(arg);
return callArgs; 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 callArgs = l_splitByTopLevelComma(call);
auto tokens = macro.body.tokenize("\n"); auto tokens = macro.body.tokenize("\n");
for (auto& line : tokens) for (auto& line : tokens)
{ {
i32 argIndex = 0; 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()) 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"; std::cout << pname << " " << callArgs[argIndex - 1] << "\n " << line << "\n";
continue; continue;
} }
if (pval == MacroParamDefault) if (pval == MacroParamDefault)
return {}; return {};
line.replaceAll(pname, pval); pval = _pval.new_replaceAll("$", "$$");
line.regexReplace(pname, pval);
} }
std::cout << "\n"; std::cout << "\n";
lines.push_back(line); lines.push_back(line);

View file

@ -120,15 +120,20 @@ namespace ostd
String& String::replaceAll(const String& what, const String& with) String& String::replaceAll(const String& what, const String& with)
{ {
while (contains(what)) if (what.len() == 0) return *this;
replaceFirst(what, with); 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; 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); i32 index = indexOf(what, startIndex);
if (index == -1) return *this; if (index < 0) return *this;
m_data.replace(index, what.len(), with.cpp_str()); m_data.replace(index, what.len(), with.cpp_str());
return *this; return *this;
} }
@ -323,10 +328,10 @@ namespace ostd
return __str.replaceAll(what, with); 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; 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 String String::new_regexReplace(const String& regex_pattern, const String& replace_with, bool case_insensitive) const

View file

@ -104,7 +104,7 @@ namespace ostd
String& addRightPadding(u32 new_string_length, char c = ' '); String& addRightPadding(u32 new_string_length, char c = ' ');
String& reverse(void); String& reverse(void);
String& replaceAll(const String& what, const String& with); 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& regexReplace(const String& regex_pattern, const String& replace_with, bool case_insensitive = false);
String& put(u32 index, char c); String& put(u32 index, char c);
String& substr(u32 start, i32 end = -1); 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_addRightPadding(u32 new_string_length, char c = ' ') const;
String new_reverse(void) const; String new_reverse(void) const;
String new_replaceAll(const String& what, const String& with) 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_regexReplace(const String& regex_pattern, const String& replace_with, bool case_insensitive = false) const;
String new_put(u32 index, char c) const; String new_put(u32 index, char c) const;
String new_substr(u32 start, i32 end = -1) const; String new_substr(u32 start, i32 end = -1) const;