From 908a138a46e39a39bb1a4aa1fcdab9a3432c0c3b Mon Sep 17 00:00:00 2001 From: Neil Date: Fri, 13 Apr 2018 08:48:23 +1000 Subject: Backport: Fix bug with regular expression searches failing to match at line start or end. This was a work-around for infinite loops when replacing empty matches and this is now the application's responsibility. Backport of changeset 6683:bcae0331720b. --- doc/ScintillaHistory.html | 8 ++++++++ src/Document.cxx | 20 ++++---------------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index a0fc4f2b6..6e41fbb67 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -543,6 +543,14 @@ when text insertion followed by caret up or down.
  • + Bugs fixed in regular expression searches in Scintilla where some matches did not occur in an + effort to avoid infinite loops when replacing on empty matches like "^" and "$". + Applications should always handle empty matches in a way that avoids infinite loops, commonly + by incrementing the search position after replacing an empty match. + SciTE fixes a bug where replacing "^" always matched on the first line even when it was an + "in selection" replace and the selection started after the line start. +
  • +
  • On Win32, a new file, ScintillaDLL.cxx, provides the DllMain function required for a stand-alone Scintilla DLL. Build and project files should include this file when producing a DLL and omit it when producing a static library or linking Scintilla statically. diff --git a/src/Document.cxx b/src/Document.cxx index 1d77f7065..1c9b1ceda 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -2537,25 +2537,13 @@ public: RESearchRange(const Document *doc_, Sci::Position minPos, Sci::Position maxPos) : doc(doc_) { increment = (minPos <= maxPos) ? 1 : -1; - // Range endpoints should not be inside DBCS characters, but just in case, move them. - startPos = doc->MovePositionOutsideChar(minPos, 1, false); - endPos = doc->MovePositionOutsideChar(maxPos, 1, false); + // Range endpoints should not be inside DBCS characters or between a CR and LF, + // but just in case, move them. + startPos = doc->MovePositionOutsideChar(minPos, 1, true); + endPos = doc->MovePositionOutsideChar(maxPos, 1, true); lineRangeStart = static_cast(doc->LineFromPosition(startPos)); lineRangeEnd = static_cast(doc->LineFromPosition(endPos)); - if ((increment == 1) && - (startPos >= doc->LineEnd(lineRangeStart)) && - (lineRangeStart < lineRangeEnd)) { - // the start position is at end of line or between line end characters. - lineRangeStart++; - startPos = static_cast(doc->LineStart(lineRangeStart)); - } else if ((increment == -1) && - (startPos <= doc->LineStart(lineRangeStart)) && - (lineRangeStart > lineRangeEnd)) { - // the start position is at beginning of line. - lineRangeStart--; - startPos = static_cast(doc->LineEnd(lineRangeStart)); - } lineRangeBreak = lineRangeEnd + increment; } Range LineRange(Sci::Line line) const { -- cgit v1.2.3