From 80f6caee8149e50aa4870c0c6d8241b86113d405 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 9 Oct 2017 22:09:41 +0800 Subject: [PATCH] Regex: move try/catch blocks inside boost specific code --- src/regex.hh | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/regex.hh b/src/regex.hh index 5ec88df9b..0d5651705 100644 --- a/src/regex.hh +++ b/src/regex.hh @@ -159,32 +159,32 @@ boost::regex_constants::match_flag_type convert_flags(RegexExecFlags flags); template bool regex_match(It begin, It end, const Regex& re) { + const bool matched = regex_match(begin, end, *re.impl()); +#ifdef REGEX_CHECK_WITH_BOOST try { - const bool matched = regex_match(begin, end, *re.impl()); -#ifdef REGEX_CHECK_WITH_BOOST if (not re.boost_impl().empty() and matched != boost::regex_match>({begin, begin, end}, {end, begin, end}, re.boost_impl())) regex_mismatch(re); -#endif - return matched; } catch (std::runtime_error& err) { throw runtime_error{format("Regex matching error: {}", err.what())}; } +#endif + return matched; } template bool regex_match(It begin, It end, MatchResults& res, const Regex& re) { - try - { - Vector captures; - const bool matched = regex_match(begin, end, captures, *re.impl()); + Vector captures; + const bool matched = regex_match(begin, end, captures, *re.impl()); #ifdef REGEX_CHECK_WITH_BOOST + try + { boost::match_results> boost_res; if (not re.boost_impl().empty() and matched != boost::regex_match>({begin, begin, end}, {end, begin, end}, @@ -192,50 +192,50 @@ bool regex_match(It begin, It end, MatchResults& res, const Regex& re) regex_mismatch(re); if (not re.boost_impl().empty() and matched) check_captures(re, boost_res, captures); -#endif - - res = matched ? MatchResults{std::move(captures)} : MatchResults{}; - return matched; } catch (std::runtime_error& err) { throw runtime_error{format("Regex matching error: {}", err.what())}; } +#endif + + res = matched ? MatchResults{std::move(captures)} : MatchResults{}; + return matched; } template bool regex_search(It begin, It end, const Regex& re, 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 + try + { auto first = (flags & RegexExecFlags::PrevAvailable) ? begin-1 : begin; if (not re.boost_impl().empty() and matched != boost::regex_search>({begin, first, end}, {end, first, end}, re.boost_impl(), convert_flags(flags))) regex_mismatch(re); -#endif - return matched; } catch (std::runtime_error& err) { throw runtime_error{format("Regex searching error: {}", err.what())}; } +#endif + return matched; } template bool regex_search(It begin, It end, MatchResults& res, const Regex& re, RegexExecFlags flags = RegexExecFlags::None) { - try - { - Vector captures; - const bool matched = regex_search(begin, end, captures, *re.impl(), flags); + Vector captures; + const bool matched = regex_search(begin, end, captures, *re.impl(), flags); #ifdef REGEX_CHECK_WITH_BOOST + try + { if (direction == MatchDirection::Forward) { auto first = (flags & RegexExecFlags::PrevAvailable) ? begin-1 : begin; @@ -247,15 +247,15 @@ bool regex_search(It begin, It end, MatchResults& res, const Regex& re, if (not re.boost_impl().empty() and matched) check_captures(re, boost_res, captures); } -#endif - - res = matched ? MatchResults{std::move(captures)} : MatchResults{}; - return matched; } catch (std::runtime_error& err) { throw runtime_error{format("Regex searching error: {}", err.what())}; } +#endif + + res = matched ? MatchResults{std::move(captures)} : MatchResults{}; + return matched; } String option_to_string(const Regex& re);