From 9a4b5de7721badb1f76db21dc58e92b81387cf38 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 3 Dec 2017 17:04:37 +0800 Subject: [PATCH] Regex: Introduce backward_regex_search helper function --- src/regex.hh | 11 +++++++++-- src/selectors.cc | 12 ++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/regex.hh b/src/regex.hh index 7fda8f0b..01d6bc79 100644 --- a/src/regex.hh +++ b/src/regex.hh @@ -136,6 +136,13 @@ bool regex_search(It begin, It end, MatchResults& res, const Regex& re, return regex_search(begin, end, res.values(), *re.impl(), flags); } +template +bool backward_regex_search(It begin, It end, MatchResults& res, const Regex& re, + RegexExecFlags flags = RegexExecFlags::None) +{ + return regex_search(std::move(begin), std::move(end), res, re, flags); +} + String option_to_string(const Regex& re); void option_from_string(StringView str, Regex& re); @@ -204,8 +211,8 @@ private: } else { - if (not regex_search(m_begin, m_next_pos, m_results, *m_regex, - m_flags | additional_flags)) + if (not backward_regex_search(m_begin, m_next_pos, m_results, *m_regex, + m_flags | additional_flags)) m_regex = nullptr; else m_next_pos = m_results[0].first; diff --git a/src/selectors.cc b/src/selectors.cc index 6074e38c..63f874da 100644 --- a/src/selectors.cc +++ b/src/selectors.cc @@ -862,14 +862,14 @@ static bool find_prev(const Buffer& buffer, const BufferIterator& pos, const Regex& ex, bool& wrapped) { if (pos != buffer.begin() and - regex_search( - buffer.begin(), pos, matches, ex, - match_flags(buffer, buffer.begin(), pos) | RegexExecFlags::NotInitialNull)) + backward_regex_search(buffer.begin(), pos, matches, ex, + match_flags(buffer, buffer.begin(), pos) | + RegexExecFlags::NotInitialNull)) return true; wrapped = true; - return regex_search( - buffer.begin(), buffer.end(), matches, ex, - match_flags(buffer, buffer.begin(), buffer.end()) | RegexExecFlags::NotInitialNull); + return backward_regex_search(buffer.begin(), buffer.end(), matches, ex, + match_flags(buffer, buffer.begin(), buffer.end()) | + RegexExecFlags::NotInitialNull); } template