You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-08 12:40:44 +00:00
Fixed RegEx search_all for zero length matches/lookahead/lookbehind
(cherry picked from commit 7b2fd342e3)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
result.push_back(match);
|
||||
last_end = match->get_end(0);
|
||||
match = search(p_subject, match->get_end(0), p_end);
|
||||
if (match->get_start(0) == last_end) {
|
||||
last_end++;
|
||||
}
|
||||
|
||||
result.push_back(match);
|
||||
match = search(p_subject, last_end, p_end);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user