diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2017-06-26 22:23:32 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-26 22:23:32 +0200 |
commit | 4b85b663394a65b1514c1a4645363e36ecf246f8 (patch) | |
tree | 8d63cc5506593ab964f1826ee39a0b125ac86411 /modules/regex | |
parent | 36548a3fa58f00a3ef301f169f237b5641bdf635 (diff) | |
parent | f01ce3276e1d5ade07107d25ddab04117ad40be8 (diff) |
Merge pull request #9393 from leezh/regex_capture_fixes
RegEx fixes #9382
Diffstat (limited to 'modules/regex')
-rw-r--r-- | modules/regex/regex.cpp | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/modules/regex/regex.cpp b/modules/regex/regex.cpp index eb9f1d2ab1..c728657d6b 100644 --- a/modules/regex/regex.cpp +++ b/modules/regex/regex.cpp @@ -590,6 +590,11 @@ struct RegExNodeGroup : public RegExNode { memdelete(childset[i]); } + virtual void test_success(RegExSearch &s, int pos) const { + + return; + } + virtual int test(RegExSearch &s, int pos) const { for (int i = 0; i < childset.size(); ++i) { @@ -598,10 +603,8 @@ struct RegExNodeGroup : public RegExNode { int res = childset[i]->test(s, pos); - if (s.complete) - return res; - if (inverse) { + s.complete = false; if (res < 0) res = pos + 1; else @@ -611,9 +614,13 @@ struct RegExNodeGroup : public RegExNode { continue; } + if (s.complete) + return res; + if (res >= 0) { if (reset_pos) res = pos; + this->test_success(s, res); return next ? next->test(s, res) : res; } } @@ -668,6 +675,12 @@ struct RegExNodeCapturing : public RegExNodeGroup { id = p_id; } + virtual void test_success(RegExSearch &s, int pos) const { + + RegExMatch::Group &ref = s.match->captures[id]; + ref.length = pos - ref.start; + } + virtual int test(RegExSearch &s, int pos) const { RegExMatch::Group &ref = s.match->captures[id]; @@ -676,13 +689,8 @@ struct RegExNodeCapturing : public RegExNodeGroup { int res = RegExNodeGroup::test(s, pos); - if (res >= 0) { - if (!s.complete) - ref.length = res - pos; - } else { + if (res < 0) ref.start = old_start; - } - return res; } |