Fix searching api.

This commit is contained in:
2026-08-03 20:34:24 +01:00
parent 8c61f186cf
commit 72d0ff85a3
3 changed files with 32 additions and 13 deletions
+1 -2
View File
@@ -46,8 +46,7 @@ struct Vase {
void clamp(Point *point); void clamp(Point *point);
void regex_search_replace( void regex_search_replace(
std::string_view pattern, std::string_view pattern, Range range,
Point start, Point end,
std::string_view replace, std::string_view options std::string_view replace, std::string_view options
); );
+29 -8
View File
@@ -44,28 +44,49 @@ std::vector<RegexMatch> regex_search(
std::string out; std::string out;
out.reserve(pattern_str.size() * 2); out.reserve(pattern_str.size() * 2);
bool escaped = false; bool escaped = false;
bool in_class = false;
for (char c : pattern_str) { bool in_quote = false;
// TODO: also dont switch out in [.] style groups. for (size_t i = 0; i < pattern_str.size(); i++) {
char c = pattern_str[i];
if (escaped) { if (escaped) {
out += c; out += c;
escaped = false; escaped = false;
continue; continue;
} }
if (c == '\\') { if (c == '\\') {
out += c; out += c;
if (i + 1 < pattern_str.size()) {
char next = pattern_str[i + 1];
if (next == 'Q')
in_quote = true;
else if (next == 'E')
in_quote = false;
out += next;
i++;
continue;
}
escaped = true; escaped = true;
continue; continue;
} }
if (in_quote) {
if (c == '.') { out += c;
continue;
}
if (c == '[') {
in_class = true;
out += c;
continue;
}
if (c == ']' && in_class) {
in_class = false;
out += c;
continue;
}
if (c == '.' && !in_class) {
out += dot; out += dot;
continue; continue;
} }
out += c; out += c;
} }
+2 -3
View File
@@ -385,11 +385,10 @@ std::vector<ReplacePart> parse_replace(AppendBuffer &buf, std::string_view s) {
} }
void Vase::regex_search_replace( void Vase::regex_search_replace(
std::string_view pattern, std::string_view pattern, Range range,
Point start, Point end,
std::string_view replace, std::string_view options std::string_view replace, std::string_view options
) { ) {
std::vector<RegexMatch> matches = regex_search(root, pattern, offset_of(start), offset_of(end), options); std::vector<RegexMatch> matches = regex_search(root, pattern, offset_of(range.start), offset_of(range.end), options);
if (matches.empty()) if (matches.empty())
return; return;