aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2018-06-10 13:32:22 +1000
committerNeil <nyamatongwe@gmail.com>2018-06-10 13:32:22 +1000
commitdc54c96dc1a32afeae5705360b7f6cc8b51c887e (patch)
treeba2b50d8e63c812661787e89dfc00f293ba8ef10 /src
parentdb30b55467d5ea84e53454adf18a0859e67a17ac (diff)
downloadscintilla-mirror-dc54c96dc1a32afeae5705360b7f6cc8b51c887e.tar.gz
Updated the code and comment for running a regex over multiple lines at once
instead of breaking up into lines. Using the preprocessor to hide the multiline code instead of comments so that it is easier to experiment with.
Diffstat (limited to 'src')
-rw-r--r--src/Document.cxx22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/Document.cxx b/src/Document.cxx
index 942903b78..31e40f7db 100644
--- a/src/Document.cxx
+++ b/src/Document.cxx
@@ -2960,14 +2960,19 @@ bool MatchOnLines(const Document *doc, const Regex &regexp, const RESearchRange
bool matched = false;
std::match_results<Iterator> match;
- // MSVC and libc++ have problems with ^ and $ matching line ends inside a range
- // If they didn't then the line by line iteration could be removed for the forwards
- // case and replaced with the following 4 lines:
- // Iterator uiStart(doc, startPos);
- // Iterator uiEnd(doc, endPos);
- // flagsMatch = MatchFlags(doc, startPos, endPos);
- // matched = std::regex_search(uiStart, uiEnd, match, regexp, flagsMatch);
-
+ // MSVC and libc++ have problems with ^ and $ matching line ends inside a range.
+ // CRLF line ends are also a problem as ^ and $ only treat LF as a line end.
+ // The std::regex::multiline option was added to C++17 to improve behaviour but
+ // has not been implemented by compiler runtimes with MSVC always in multiline
+ // mode and libc++ and libstdc++ always in single-line mode.
+ // If multiline regex worked well then the line by line iteration could be removed
+ // for the forwards case and replaced with the following 4 lines:
+#ifdef REGEX_MULTILINE
+ Iterator itStart(doc, resr.startPos);
+ Iterator itEnd(doc, resr.endPos);
+ const std::regex_constants::match_flag_type flagsMatch = MatchFlags(doc, resr.startPos, resr.endPos);
+ matched = std::regex_search(itStart, itEnd, match, regexp, flagsMatch);
+#else
// Line by line.
for (Sci::Line line = resr.lineRangeStart; line != resr.lineRangeBreak; line += resr.increment) {
const Range lineRange = resr.LineRange(line);
@@ -2996,6 +3001,7 @@ bool MatchOnLines(const Document *doc, const Regex &regexp, const RESearchRange
break;
}
}
+#endif
if (matched) {
for (size_t co = 0; co < match.size(); co++) {
search.bopat[co] = match[co].first.Pos();