Fix searching api.
This commit is contained in:
+1
-2
@@ -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
@@ -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
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user