template<typename Iterator, typename Regex>
bool MatchOnLines(const Document *doc, const Regex ®exp, const RESearchRange &resr, RESearch &search) {
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);
// Line by line.
for (Sci::Line line = resr.lineRangeStart; line != resr.lineRangeBreak; line += resr.increment) {
template<typename Iterator, typename Regex>
bool MatchOnLines(const Document *doc, const Regex ®exp, const RESearchRange &resr, RESearch &search) {
std::match_results<Iterator> match; Iterator uiStart(doc, resr.startPos);
Iterator uiEnd(doc, resr.endPos);
std::regex_constants::match_flag_type flagsMatch = MatchFlags(doc, resr.startPos, resr.endPos);
bool matched = std::regex_search(uiStart, uiEnd, match, regexp, flagsMatch); if (matched) {
for (size_t co = 0; co < match.size(); co++) {
search.bopat[co] = match[co].first.Pos();
search.eopat[co] = match[co].second.PosRoundUp();
Sci::Position lenMatch = search.eopat[co] - search.bopat[co];
search.pat[co].resize(lenMatch);
for (Sci::Position iPos = 0; iPos < lenMatch; iPos++) {
search.pat[co][iPos] = doc->CharAt(iPos + search.bopat[co]);
}
}
}
return matched;
}
However, it doesn’t work with the <regex> implementation in the standard library for GCC 7.3 as provided by current Fedora Linux 27.
With MSVC, it has problems with files containing CRLF line ends. Search the file “a\r\n” for “$” and it returns 2: between the CR and LF. That, by itself, could be worked around by nudging the match out of the composite line end. But worse, searching “a\r\n” for “a$” doesn’t match.
Its possible that the UTF8Iterator class could be enhanced to report “\r\n” as a single “\n” but that appears complex.
Neil