summaryrefslogtreecommitdiffstats
path: root/modules/regex/regex.cpp
diff options
context:
space:
mode:
authorSofox <sofoxx@gmail.com>2023-12-05 13:21:57 +0000
committerSofox <sofoxx@gmail.com>2023-12-08 17:54:58 +0000
commit7b2fd342e32a87ae57c16f568709dc4bb3fae2a5 (patch)
tree78f1845c6c2d6af3bfcd6cce2d93764d78937ca1 /modules/regex/regex.cpp
parentc4f872e38e577d8d6fedeaba99b144590113f751 (diff)
downloadredot-engine-7b2fd342e32a87ae57c16f568709dc4bb3fae2a5.tar.gz
Fixed RegEx search_all for zero length matches/lookahead/lookbehind
Diffstat (limited to 'modules/regex/regex.cpp')
-rw-r--r--modules/regex/regex.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/modules/regex/regex.cpp b/modules/regex/regex.cpp
index 704c107f20..d49578d2a9 100644
--- a/modules/regex/regex.cpp
+++ b/modules/regex/regex.cpp
@@ -270,16 +270,18 @@ Ref<RegExMatch> RegEx::search(const String &p_subject, int p_offset, int p_end)
TypedArray<RegExMatch> RegEx::search_all(const String &p_subject, int p_offset, int p_end) const {
ERR_FAIL_COND_V_MSG(p_offset < 0, Array(), "RegEx search offset must be >= 0");
- int last_end = -1;
+ int last_end = 0;
TypedArray<RegExMatch> result;
Ref<RegExMatch> match = search(p_subject, p_offset, p_end);
+
while (match.is_valid()) {
- if (last_end == match->get_end(0)) {
- break;
+ last_end = match->get_end(0);
+ if (match->get_start(0) == last_end) {
+ last_end++;
}
+
result.push_back(match);
- last_end = match->get_end(0);
- match = search(p_subject, match->get_end(0), p_end);
+ match = search(p_subject, last_end, p_end);
}
return result;
}