diff options
author | Zufu Liu <unknown> | 2023-12-21 16:00:00 +1100 |
---|---|---|
committer | Zufu Liu <unknown> | 2023-12-21 16:00:00 +1100 |
commit | 8e55cc0c973cc2fbaac8cca1505524b86ce58dff (patch) | |
tree | 0cf01d056b0c92de62b811466495a42d82a7879b /src | |
parent | 1b153f8d8d4b2f09afc2d039256c958e94bd3b05 (diff) | |
download | scintilla-mirror-8e55cc0c973cc2fbaac8cca1505524b86ce58dff.tar.gz |
Bug [#2405]. Avoid character fragments in regular expression search results.
Diffstat (limited to 'src')
-rw-r--r-- | src/Document.cxx | 9 | ||||
-rw-r--r-- | src/RESearch.cxx | 16 | ||||
-rw-r--r-- | src/RESearch.h | 1 |
3 files changed, 20 insertions, 6 deletions
diff --git a/src/Document.cxx b/src/Document.cxx index d67cac25e..aea2cfd0b 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -2883,6 +2883,9 @@ public: else return pdoc->CharAt(index); } + Sci::Position MovePositionOutsideChar(Sci::Position pos, Sci::Position moveDir) const noexcept override { + return pdoc->MovePositionOutsideChar(pos, moveDir, false); + } }; #ifndef NO_CXX11_REGEX @@ -3277,8 +3280,7 @@ Sci::Position BuiltinRegex::FindText(Document *doc, Sci::Position minPos, Sci::P search.SetLineRange(lineStartPos, lineEndPos); int success = search.Execute(di, startOfLine, endOfLine); if (success) { - // Ensure only whole characters selected - Sci::Position endPos = doc->MovePositionOutsideChar(search.eopat[0], 1, false); + Sci::Position endPos = search.eopat[0]; // There can be only one start of a line, so no need to look for last match in line if ((resr.increment == -1) && !searchforLineStart) { // Check for the last match on this line. @@ -3292,14 +3294,13 @@ Sci::Position BuiltinRegex::FindText(Document *doc, Sci::Position minPos, Sci::P } success = search.Execute(di, pos, endOfLine); if (success) { - endPos = doc->MovePositionOutsideChar(search.eopat[0], 1, false); + endPos = search.eopat[0]; } else { search.bopat = bopat; search.eopat = eopat; } } } - search.eopat[0] = endPos; pos = search.bopat[0]; lenRet = endPos - pos; break; diff --git a/src/RESearch.cxx b/src/RESearch.cxx index 7b2701aba..5a509ab6e 100644 --- a/src/RESearch.cxx +++ b/src/RESearch.cxx @@ -769,8 +769,15 @@ int RESearch::Execute(const CharacterIndexer &ci, Sci::Position lp, Sci::Positio default: /* regular matching all the way. */ while (lp < endp) { ep = PMatch(ci, lp, endp, ap); - if (ep != NOTFOUND) - break; + if (ep != NOTFOUND) { + // fix match started from middle of character like DBCS trailing ASCII byte + const Sci::Position pos = ci.MovePositionOutsideChar(lp, -1); + if (pos != lp) { + ep = NOTFOUND; + } else { + break; + } + } lp++; } break; @@ -791,6 +798,7 @@ int RESearch::Execute(const CharacterIndexer &ci, Sci::Position lp, Sci::Positio } } + ep = ci.MovePositionOutsideChar(ep, 1); bopat[0] = lp; eopat[0] = ep; return 1; @@ -865,9 +873,13 @@ Sci::Position RESearch::PMatch(const CharacterIndexer &ci, Sci::Position lp, Sci return NOTFOUND; break; case BOT: + if (lp != ci.MovePositionOutsideChar(lp, -1)) { + return NOTFOUND; + } bopat[static_cast<unsigned char>(*ap++)] = lp; break; case EOT: + lp = ci.MovePositionOutsideChar(lp, 1); eopat[static_cast<unsigned char>(*ap++)] = lp; break; case BOW: diff --git a/src/RESearch.h b/src/RESearch.h index e3a9c8110..a6b9ac22e 100644 --- a/src/RESearch.h +++ b/src/RESearch.h @@ -14,6 +14,7 @@ namespace Scintilla::Internal { class CharacterIndexer { public: virtual char CharAt(Sci::Position index) const=0; + virtual Sci::Position MovePositionOutsideChar(Sci::Position pos, [[maybe_unused]] Sci::Position moveDir) const noexcept=0; }; class RESearch { |