diff options
| author | Maxime Coste <mawww@kakoune.org> | 2017-11-01 14:08:03 +0800 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2017-11-01 14:09:39 +0800 |
| commit | 51de90f366685e6112866f34d330495c2aa54571 (patch) | |
| tree | f344718ec8e369af720c792f0af1eb1921ea0f59 /src/regex.hh | |
| parent | 2b295a265ea3c5e6ec5b5b6d8bdfc02fd0c7a4d6 (diff) | |
Regex: Remove boost related code
Diffstat (limited to 'src/regex.hh')
| -rw-r--r-- | src/regex.hh | 123 |
1 files changed, 2 insertions, 121 deletions
diff --git a/src/regex.hh b/src/regex.hh index 0d565170..8e6c2dac 100644 --- a/src/regex.hh +++ b/src/regex.hh @@ -4,15 +4,6 @@ #include "string.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 <boost/regex.hpp> -#endif - namespace Kakoune { @@ -36,17 +27,9 @@ public: const CompiledRegex* impl() const { return m_impl.get(); } -#ifdef REGEX_CHECK_WITH_BOOST - using BoostImpl = boost::basic_regex<wchar_t, boost::c_regex_traits<wchar_t>>; - const BoostImpl& boost_impl() const { return m_boost_impl; } -#endif - private: RefPtr<CompiledRegex> m_impl; String m_str; -#ifdef REGEX_CHECK_WITH_BOOST - BoostImpl m_boost_impl; -#endif }; template<typename Iterator> @@ -124,56 +107,10 @@ 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<typename It> -using RegexUtf8It = utf8::iterator<It, wchar_t, ssize_t>; - -template<typename It> -void check_captures(const Regex& re, const boost::match_results<RegexUtf8It<It>>& res, const Vector<It>& captures) -{ - if (res.size() > captures.size() * 2) - return regex_mismatch(re); - - for (size_t i = 0; i < res.size(); ++i) - { - if (not res[i].matched) - { - if (captures[i*2] != It{} or captures[i*2+1] != It{}) - regex_mismatch(re); - continue; - } - - if (res[i].first != captures[i*2]) - regex_mismatch(re); - if (res[i].second != captures[i*2+1]) - regex_mismatch(re); - } -} - -boost::regbase::flag_type convert_flags(RegexCompileFlags flags); -boost::regex_constants::match_flag_type convert_flags(RegexExecFlags flags); -#endif - template<typename It> 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 - { - if (not re.boost_impl().empty() and - matched != boost::regex_match<RegexUtf8It<It>>({begin, begin, end}, {end, begin, end}, - re.boost_impl())) - regex_mismatch(re); - } - catch (std::runtime_error& err) - { - throw runtime_error{format("Regex matching error: {}", err.what())}; - } -#endif - return matched; + return regex_match(begin, end, *re.impl()); } template<typename It> @@ -181,24 +118,6 @@ bool regex_match(It begin, It end, MatchResults<It>& res, const Regex& re) { Vector<It> captures; const bool matched = regex_match(begin, end, captures, *re.impl()); - -#ifdef REGEX_CHECK_WITH_BOOST - try - { - boost::match_results<RegexUtf8It<It>> boost_res; - if (not re.boost_impl().empty() and - matched != boost::regex_match<RegexUtf8It<It>>({begin, begin, end}, {end, begin, end}, - boost_res, re.boost_impl())) - regex_mismatch(re); - if (not re.boost_impl().empty() and matched) - check_captures(re, boost_res, captures); - } - catch (std::runtime_error& err) - { - throw runtime_error{format("Regex matching error: {}", err.what())}; - } -#endif - res = matched ? MatchResults<It>{std::move(captures)} : MatchResults<It>{}; return matched; } @@ -207,23 +126,7 @@ template<typename It> bool regex_search(It begin, It end, const Regex& re, RegexExecFlags flags = RegexExecFlags::None) { - 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<RegexUtf8It<It>>({begin, first, end}, {end, first, end}, - re.boost_impl(), convert_flags(flags))) - regex_mismatch(re); - } - catch (std::runtime_error& err) - { - throw runtime_error{format("Regex searching error: {}", err.what())}; - } -#endif - return matched; + return regex_search(begin, end, *re.impl(), flags); } template<typename It, MatchDirection direction = MatchDirection::Forward> @@ -232,28 +135,6 @@ bool regex_search(It begin, It end, MatchResults<It>& res, const Regex& re, { Vector<It> captures; const bool matched = regex_search<It, direction>(begin, end, captures, *re.impl(), flags); - -#ifdef REGEX_CHECK_WITH_BOOST - try - { - if (direction == MatchDirection::Forward) - { - auto first = (flags & RegexExecFlags::PrevAvailable) ? begin-1 : begin; - boost::match_results<RegexUtf8It<It>> boost_res; - if (not re.boost_impl().empty() and - matched != boost::regex_search<RegexUtf8It<It>>({begin, first, end}, {end, first, end}, - boost_res, re.boost_impl(), convert_flags(flags))) - regex_mismatch(re); - if (not re.boost_impl().empty() and matched) - check_captures(re, boost_res, captures); - } - } - catch (std::runtime_error& err) - { - throw runtime_error{format("Regex searching error: {}", err.what())}; - } -#endif - res = matched ? MatchResults<It>{std::move(captures)} : MatchResults<It>{}; return matched; } |
