mirror of
https://github.com/mawww/kakoune.git
synced 2024-12-20 10:01:57 +03:00
Regex: move try/catch blocks inside boost specific code
This commit is contained in:
parent
dd9e43e6f9
commit
80f6caee81
40
src/regex.hh
40
src/regex.hh
@ -158,33 +158,33 @@ boost::regex_constants::match_flag_type convert_flags(RegexExecFlags flags);
|
|||||||
|
|
||||||
template<typename It>
|
template<typename It>
|
||||||
bool regex_match(It begin, It end, const Regex& re)
|
bool regex_match(It begin, It end, const Regex& re)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
const bool matched = regex_match(begin, end, *re.impl());
|
const bool matched = regex_match(begin, end, *re.impl());
|
||||||
#ifdef REGEX_CHECK_WITH_BOOST
|
#ifdef REGEX_CHECK_WITH_BOOST
|
||||||
|
try
|
||||||
|
{
|
||||||
if (not re.boost_impl().empty() and
|
if (not re.boost_impl().empty() and
|
||||||
matched != boost::regex_match<RegexUtf8It<It>>({begin, begin, end}, {end, begin, end},
|
matched != boost::regex_match<RegexUtf8It<It>>({begin, begin, end}, {end, begin, end},
|
||||||
re.boost_impl()))
|
re.boost_impl()))
|
||||||
regex_mismatch(re);
|
regex_mismatch(re);
|
||||||
#endif
|
|
||||||
return matched;
|
|
||||||
}
|
}
|
||||||
catch (std::runtime_error& err)
|
catch (std::runtime_error& err)
|
||||||
{
|
{
|
||||||
throw runtime_error{format("Regex matching error: {}", err.what())};
|
throw runtime_error{format("Regex matching error: {}", err.what())};
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
return matched;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename It>
|
template<typename It>
|
||||||
bool regex_match(It begin, It end, MatchResults<It>& res, const Regex& re)
|
bool regex_match(It begin, It end, MatchResults<It>& res, const Regex& re)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
Vector<It> captures;
|
Vector<It> captures;
|
||||||
const bool matched = regex_match(begin, end, captures, *re.impl());
|
const bool matched = regex_match(begin, end, captures, *re.impl());
|
||||||
|
|
||||||
#ifdef REGEX_CHECK_WITH_BOOST
|
#ifdef REGEX_CHECK_WITH_BOOST
|
||||||
|
try
|
||||||
|
{
|
||||||
boost::match_results<RegexUtf8It<It>> boost_res;
|
boost::match_results<RegexUtf8It<It>> boost_res;
|
||||||
if (not re.boost_impl().empty() and
|
if (not re.boost_impl().empty() and
|
||||||
matched != boost::regex_match<RegexUtf8It<It>>({begin, begin, end}, {end, begin, end},
|
matched != boost::regex_match<RegexUtf8It<It>>({begin, begin, end}, {end, begin, end},
|
||||||
@ -192,50 +192,50 @@ bool regex_match(It begin, It end, MatchResults<It>& res, const Regex& re)
|
|||||||
regex_mismatch(re);
|
regex_mismatch(re);
|
||||||
if (not re.boost_impl().empty() and matched)
|
if (not re.boost_impl().empty() and matched)
|
||||||
check_captures(re, boost_res, captures);
|
check_captures(re, boost_res, captures);
|
||||||
#endif
|
|
||||||
|
|
||||||
res = matched ? MatchResults<It>{std::move(captures)} : MatchResults<It>{};
|
|
||||||
return matched;
|
|
||||||
}
|
}
|
||||||
catch (std::runtime_error& err)
|
catch (std::runtime_error& err)
|
||||||
{
|
{
|
||||||
throw runtime_error{format("Regex matching error: {}", err.what())};
|
throw runtime_error{format("Regex matching error: {}", err.what())};
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
res = matched ? MatchResults<It>{std::move(captures)} : MatchResults<It>{};
|
||||||
|
return matched;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename It>
|
template<typename It>
|
||||||
bool regex_search(It begin, It end, const Regex& re,
|
bool regex_search(It begin, It end, const Regex& re,
|
||||||
RegexExecFlags flags = RegexExecFlags::None)
|
RegexExecFlags flags = RegexExecFlags::None)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
const bool matched = regex_search(begin, end, *re.impl(), flags);
|
const bool matched = regex_search(begin, end, *re.impl(), flags);
|
||||||
|
|
||||||
#ifdef REGEX_CHECK_WITH_BOOST
|
#ifdef REGEX_CHECK_WITH_BOOST
|
||||||
|
try
|
||||||
|
{
|
||||||
auto first = (flags & RegexExecFlags::PrevAvailable) ? begin-1 : begin;
|
auto first = (flags & RegexExecFlags::PrevAvailable) ? begin-1 : begin;
|
||||||
if (not re.boost_impl().empty() and
|
if (not re.boost_impl().empty() and
|
||||||
matched != boost::regex_search<RegexUtf8It<It>>({begin, first, end}, {end, first, end},
|
matched != boost::regex_search<RegexUtf8It<It>>({begin, first, end}, {end, first, end},
|
||||||
re.boost_impl(), convert_flags(flags)))
|
re.boost_impl(), convert_flags(flags)))
|
||||||
regex_mismatch(re);
|
regex_mismatch(re);
|
||||||
#endif
|
|
||||||
return matched;
|
|
||||||
}
|
}
|
||||||
catch (std::runtime_error& err)
|
catch (std::runtime_error& err)
|
||||||
{
|
{
|
||||||
throw runtime_error{format("Regex searching error: {}", err.what())};
|
throw runtime_error{format("Regex searching error: {}", err.what())};
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
return matched;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename It, MatchDirection direction = MatchDirection::Forward>
|
template<typename It, MatchDirection direction = MatchDirection::Forward>
|
||||||
bool regex_search(It begin, It end, MatchResults<It>& res, const Regex& re,
|
bool regex_search(It begin, It end, MatchResults<It>& res, const Regex& re,
|
||||||
RegexExecFlags flags = RegexExecFlags::None)
|
RegexExecFlags flags = RegexExecFlags::None)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
Vector<It> captures;
|
Vector<It> captures;
|
||||||
const bool matched = regex_search<It, direction>(begin, end, captures, *re.impl(), flags);
|
const bool matched = regex_search<It, direction>(begin, end, captures, *re.impl(), flags);
|
||||||
|
|
||||||
#ifdef REGEX_CHECK_WITH_BOOST
|
#ifdef REGEX_CHECK_WITH_BOOST
|
||||||
|
try
|
||||||
|
{
|
||||||
if (direction == MatchDirection::Forward)
|
if (direction == MatchDirection::Forward)
|
||||||
{
|
{
|
||||||
auto first = (flags & RegexExecFlags::PrevAvailable) ? begin-1 : begin;
|
auto first = (flags & RegexExecFlags::PrevAvailable) ? begin-1 : begin;
|
||||||
@ -247,15 +247,15 @@ bool regex_search(It begin, It end, MatchResults<It>& res, const Regex& re,
|
|||||||
if (not re.boost_impl().empty() and matched)
|
if (not re.boost_impl().empty() and matched)
|
||||||
check_captures(re, boost_res, captures);
|
check_captures(re, boost_res, captures);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
res = matched ? MatchResults<It>{std::move(captures)} : MatchResults<It>{};
|
|
||||||
return matched;
|
|
||||||
}
|
}
|
||||||
catch (std::runtime_error& err)
|
catch (std::runtime_error& err)
|
||||||
{
|
{
|
||||||
throw runtime_error{format("Regex searching error: {}", err.what())};
|
throw runtime_error{format("Regex searching error: {}", err.what())};
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
res = matched ? MatchResults<It>{std::move(captures)} : MatchResults<It>{};
|
||||||
|
return matched;
|
||||||
}
|
}
|
||||||
|
|
||||||
String option_to_string(const Regex& re);
|
String option_to_string(const Regex& re);
|
||||||
|
Loading…
Reference in New Issue
Block a user