Skip to content

Commit 938ad2b

Browse files
committed
fixed replace_all
1 parent 725d905 commit 938ad2b

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

pcre2_regex.cc

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,14 @@ void PCRERegex::replace_all(std::string &text, const std::string &replacement) c
6363
std::string::size_type last = 0;
6464
auto pairs = all_matches(text);
6565
for(auto &x:pairs) {
66-
if (x.first >= last) {
67-
result.append(text.substr(last, x.first - last));
68-
result.append(replacement);
69-
last = x.first + x.second;
70-
}
66+
result.append(text.substr(last, x.first - last));
67+
last = x.first + x.second;
68+
result.append(replacement);
7169
}
7270
result.append(text.substr(last));
7371
text = result;
7472
}
7573

76-
7774
std::vector<std::pair<std::string::size_type, std::string::size_type>> PCRERegex::all_matches(const std::string &text) const
7875
{
7976
std::vector<std::pair<std::string::size_type, std::string::size_type>> result;
@@ -94,6 +91,5 @@ std::vector<std::pair<std::string::size_type, std::string::size_type>> PCRERegex
9491
} while (rc >= 0 && start_offset < text_length && match_length > 0);
9592
pcre2_match_data_free_8(match_data);
9693
return result;
97-
9894
}
9995

0 commit comments

Comments
 (0)