From e362eb4f3b81f5b0b4ed428c62f60e303d595747 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 13 Oct 2014 19:40:27 +0100 Subject: [PATCH] Add a disabled wrapper for using std regex instead of boost --- src/regex.hh | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/src/regex.hh b/src/regex.hh index a3e911bd..87e1f9f9 100644 --- a/src/regex.hh +++ b/src/regex.hh @@ -3,26 +3,50 @@ #include "string.hh" -#if 0 +#ifdef KAK_USE_STDREGEX #include -namespace kak_regex_ns = std; #else #include -namespace kak_regex_ns = boost; #endif namespace Kakoune { -using Regex = kak_regex_ns::regex; +#ifdef KAK_USE_STDREGEX +// Regex that keeps track of its string representation +struct Regex : std::regex +{ + Regex() = default; + + explicit Regex(StringView re, flag_type flags = ECMAScript) + : std::regex(re.begin(), re.end(), flags), m_str(re) {} + + template + Regex(Iterator begin, Iterator end, flag_type flags = ECMAScript) + : std::regex(begin, end, flags), m_str(begin, end) {} + + bool empty() const { return m_str.empty(); } + bool operator==(const Regex& other) { return m_str == other.m_str; } + bool operator!=(const Regex& other) { return m_str != other.m_str; } + + StringView str() const { return m_str; } + +private: + String m_str; +}; +namespace regex_ns = std; +#else +namespace regex_ns = boost; +using Regex = boost::regex; +#endif template -using RegexIterator = kak_regex_ns::regex_iterator; +using RegexIterator = regex_ns::regex_iterator; template -using MatchResults = kak_regex_ns::match_results; +using MatchResults = regex_ns::match_results; -using RegexError = kak_regex_ns::regex_error; +using RegexError = regex_ns::regex_error; String option_to_string(const Regex& re); void option_from_string(StringView str, Regex& re);