diff --git a/src/regex.cc b/src/regex.cc index f7ba0e48..8809757a 100644 --- a/src/regex.cc +++ b/src/regex.cc @@ -1,10 +1,13 @@ #include "regex.hh" +#ifdef REGEX_CHECK_WITH_BOOST #include "buffer_utils.hh" +#endif namespace Kakoune { +#ifdef REGEX_CHECK_WITH_BOOST using Utf8It = RegexUtf8It; boost::regbase::flag_type convert_flags(RegexCompileFlags flags) @@ -41,12 +44,19 @@ boost::regex_constants::match_flag_type convert_flags(RegexExecFlags flags) return res; } +void regex_mismatch(const Regex& re) +{ + write_to_debug_buffer(format("regex mismatch for '{}'", re.str())); +} +#endif + 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)} -{ -} catch (std::runtime_error& err) { throw regex_error(err.what()); } + m_str{re.str()} +#ifdef REGEX_CHECK_WITH_BOOST + , m_boost_impl{Utf8It{re.begin(), re}, Utf8It{re.end(), re}, convert_flags(flags)} +#endif +{} catch (std::runtime_error& err) { throw regex_error(err.what()); } String option_to_string(const Regex& re) { @@ -58,9 +68,4 @@ void option_from_string(StringView str, Regex& re) re = Regex{str}; } -void regex_mismatch(const Regex& re) -{ - write_to_debug_buffer(format("regex mismatch for '{}'", re.str())); -} - } diff --git a/src/regex.hh b/src/regex.hh index fc9d3176..d481ec7d 100644 --- a/src/regex.hh +++ b/src/regex.hh @@ -2,12 +2,16 @@ #define regex_hh_INCLUDED #include "string.hh" -#include "string_utils.hh" -#include "exception.hh" -#include "utf8_iterator.hh" #include "regex_impl.hh" +#define REGEX_CHECK_WITH_BOOST + +#ifdef REGEX_CHECK_WITH_BOOST +#include "exception.hh" +#include "string_utils.hh" +#include "utf8_iterator.hh" #include +#endif namespace Kakoune { @@ -31,13 +35,17 @@ public: const CompiledRegex* impl() const { return m_impl.get(); } +#ifdef REGEX_CHECK_WITH_BOOST using BoostImpl = boost::basic_regex>; const BoostImpl& boost_impl() const { return m_boost_impl; } +#endif private: RefPtr m_impl; String m_str; +#ifdef REGEX_CHECK_WITH_BOOST BoostImpl m_boost_impl; +#endif }; template @@ -115,6 +123,7 @@ inline RegexExecFlags match_flags(bool bol, bool eol, bool bow, bool eow) (eow ? RegexExecFlags::None : RegexExecFlags::NotEndOfWord); } +#ifdef REGEX_CHECK_WITH_BOOST void regex_mismatch(const Regex& re); template @@ -144,6 +153,7 @@ void check_captures(const Regex& re, const boost::match_results> boost::regbase::flag_type convert_flags(RegexCompileFlags flags); boost::regex_constants::match_flag_type convert_flags(RegexExecFlags flags); +#endif template bool regex_match(It begin, It end, const Regex& re) @@ -151,10 +161,12 @@ bool regex_match(It begin, It end, const Regex& re) 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) @@ -171,6 +183,7 @@ bool regex_match(It begin, It end, MatchResults& res, const Regex& re) Vector captures; const bool matched = regex_match(begin, end, captures, *re.impl()); +#ifdef REGEX_CHECK_WITH_BOOST boost::match_results> boost_res; if (not re.boost_impl().empty() and matched != boost::regex_match>({begin, begin, end}, {end, begin, end}, @@ -178,6 +191,7 @@ 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; @@ -196,11 +210,13 @@ bool regex_search(It begin, It end, const Regex& re, { const bool matched = regex_search(begin, end, *re.impl(), flags); +#ifdef REGEX_CHECK_WITH_BOOST 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) @@ -218,6 +234,7 @@ bool regex_search(It begin, It end, MatchResults& res, const Regex& re, Vector captures; const bool matched = regex_search(begin, end, captures, *re.impl(), flags); +#ifdef REGEX_CHECK_WITH_BOOST auto first = (flags & RegexExecFlags::PrevAvailable) ? begin-1 : begin; boost::match_results> boost_res; if (not re.boost_impl().empty() and @@ -226,6 +243,7 @@ bool regex_search(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; diff --git a/src/regex_impl.cc b/src/regex_impl.cc index 1b056e83..0d6fcf2d 100644 --- a/src/regex_impl.cc +++ b/src/regex_impl.cc @@ -6,6 +6,7 @@ #include "unit_tests.hh" #include "utf8.hh" #include "utf8_iterator.hh" +#include "string_utils.hh" #include "vector.hh" namespace Kakoune