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 regex_search_replace(
std::string_view pattern,
Point start, Point end,
std::string_view pattern, Range range,
std::string_view replace, std::string_view options
);
+29 -8
View File
@@ -44,28 +44,49 @@ std::vector<RegexMatch> regex_search(
std::string out;
out.reserve(pattern_str.size() * 2);
bool escaped = false;
for (char c : pattern_str) {
// TODO: also dont switch out in [.] style groups.
bool in_class = false;
bool in_quote = false;
for (size_t i = 0; i < pattern_str.size(); i++) {
char c = pattern_str[i];
if (escaped) {
out += c;
escaped = false;
continue;
}
if (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;
continue;
}
if (c == '.') {
if (in_quote) {
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;
continue;
}
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(
std::string_view pattern,
Point start, Point end,
std::string_view pattern, Range range,
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())
return;