diff options
| author | Maxime Coste <mawww@kakoune.org> | 2017-10-09 14:04:14 +0800 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2017-11-01 14:05:14 +0800 |
| commit | 065bbc8f5903c39a7ed4cca60d721dc92741154a (patch) | |
| tree | f9379f55c4fa5809c01259f636662e1097ffee81 /src/regex.cc | |
| parent | 9305fa136918010fab36c09e7174c5a45b422141 (diff) | |
Regex: switch to custom impl, use boost for checking
Diffstat (limited to 'src/regex.cc')
| -rw-r--r-- | src/regex.cc | 49 |
1 files changed, 38 insertions, 11 deletions
diff --git a/src/regex.cc b/src/regex.cc index a53dc498..f7ba0e48 100644 --- a/src/regex.cc +++ b/src/regex.cc @@ -1,6 +1,5 @@ #include "regex.hh" -#include "exception.hh" #include "buffer_utils.hh" namespace Kakoune @@ -8,17 +7,45 @@ namespace Kakoune using Utf8It = RegexUtf8It<const char*>; -Regex::Regex(StringView re, flag_type flags) try - : RegexBase{Utf8It{re.begin(), re}, Utf8It{re.end(), re}, flags}, m_str{re.str()} +boost::regbase::flag_type convert_flags(RegexCompileFlags flags) +{ + boost::regbase::flag_type res = boost::regbase::ECMAScript; + if (flags & RegexCompileFlags::NoSubs) + res |= boost::regbase::nosubs; + if (flags & RegexCompileFlags::Optimize) + res |= boost::regbase::optimize; + return res; +} + +boost::regex_constants::match_flag_type convert_flags(RegexExecFlags flags) +{ + boost::regex_constants::match_flag_type res = boost::regex_constants::match_default; + + if (flags & RegexExecFlags::NotBeginOfLine) + res |= boost::regex_constants::match_not_bol; + if (flags & RegexExecFlags::NotEndOfLine) + res |= boost::regex_constants::match_not_eol; + if (flags & RegexExecFlags::NotBeginOfWord) + res |= boost::regex_constants::match_not_bow; + if (flags & RegexExecFlags::NotEndOfWord) + res |= boost::regex_constants::match_not_eow; + if (flags & RegexExecFlags::NotBeginOfSubject) + res |= boost::regex_constants::match_not_bob; + if (flags & RegexExecFlags::NotInitialNull) + res |= boost::regex_constants::match_not_initial_null; + if (flags & RegexExecFlags::AnyMatch) + res |= boost::regex_constants::match_any; + if (flags & RegexExecFlags::PrevAvailable) + res |= boost::regex_constants::match_prev_avail; + + return res; +} + +Regex::Regex(StringView re, RegexCompileFlags flags) try + : m_impl{new CompiledRegex{compile_regex(re, flags)}}, + m_str{re.str()}, + m_boost_impl{Utf8It{re.begin(), re}, Utf8It{re.end(), re}, convert_flags(flags)} { - try - { - m_impl = new CompiledRegex{compile_regex(re)}; - } - catch (runtime_error& err) - { - write_to_debug_buffer(err.what()); - } } catch (std::runtime_error& err) { throw regex_error(err.what()); } String option_to_string(const Regex& re) |
