From c1d7f79a52b3fe1198574c017ac6a2eb6ceac0c6 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 6 Sep 2016 13:55:14 +0100 Subject: [PATCH] Do not let boost regex errors propagate, convert them to Kakoune errors. --- src/regex.hh | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/regex.hh b/src/regex.hh index 8790baec..d2b37b54 100644 --- a/src/regex.hh +++ b/src/regex.hh @@ -104,14 +104,28 @@ template bool regex_match(It begin, It end, const Regex& re) { using Utf8It = RegexUtf8It; - return boost::regex_match(Utf8It{begin, begin, end}, Utf8It{end, begin, end}, re); + try + { + return boost::regex_match(Utf8It{begin, begin, end}, Utf8It{end, begin, end}, re); + } + catch (std::runtime_error& err) + { + throw runtime_error{format("Regex matching error: {}", err.what())}; + } } template bool regex_match(It begin, It end, MatchResults& res, const Regex& re) { using Utf8It = RegexUtf8It; - return boost::regex_match(Utf8It{begin, begin, end}, Utf8It{end, begin, end}, res, re); + try + { + return boost::regex_match(Utf8It{begin, begin, end}, Utf8It{end, begin, end}, res, re); + } + catch (std::runtime_error& err) + { + throw runtime_error{format("Regex matching error: {}", err.what())}; + } } template @@ -119,7 +133,14 @@ bool regex_search(It begin, It end, const Regex& re, RegexConstant::match_flag_type flags = RegexConstant::match_default) { using Utf8It = RegexUtf8It; - return boost::regex_search(Utf8It{begin, begin, end}, Utf8It{end, begin, end}, re); + try + { + return boost::regex_search(Utf8It{begin, begin, end}, Utf8It{end, begin, end}, re); + } + catch (std::runtime_error& err) + { + throw runtime_error{format("Regex searching error: {}", err.what())}; + } } template @@ -127,7 +148,14 @@ bool regex_search(It begin, It end, MatchResults& res, const Regex& re, RegexConstant::match_flag_type flags = RegexConstant::match_default) { using Utf8It = RegexUtf8It; - return boost::regex_search(Utf8It{begin, begin, end}, Utf8It{end, begin, end}, res, re); + try + { + return boost::regex_search(Utf8It{begin, begin, end}, Utf8It{end, begin, end}, res, re); + } + catch (std::runtime_error& err) + { + throw runtime_error{format("Regex searching error: {}", err.what())}; + } } String option_to_string(const Regex& re);