Regex: Introduce backward_regex_search helper function

This commit is contained in:
Maxime Coste 2017-12-03 17:04:37 +08:00
parent b34bb6b794
commit 9a4b5de772
2 changed files with 15 additions and 8 deletions

View File

@ -136,6 +136,13 @@ bool regex_search(It begin, It end, MatchResults<It>& res, const Regex& re,
return regex_search<It, direction>(begin, end, res.values(), *re.impl(), flags);
}
template<typename It>
bool backward_regex_search(It begin, It end, MatchResults<It>& res, const Regex& re,
RegexExecFlags flags = RegexExecFlags::None)
{
return regex_search<It, MatchDirection::Backward>(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,7 +211,7 @@ private:
}
else
{
if (not regex_search<Iterator, MatchDirection::Backward>(m_begin, m_next_pos, m_results, *m_regex,
if (not backward_regex_search(m_begin, m_next_pos, m_results, *m_regex,
m_flags | additional_flags))
m_regex = nullptr;
else

View File

@ -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<BufferIterator, MatchDirection::Backward>(
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<BufferIterator, MatchDirection::Backward>(
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<MatchDirection direction>