Add a disabled wrapper for using std regex instead of boost

This commit is contained in:
Maxime Coste 2014-10-13 19:40:27 +01:00
parent eb0d03f437
commit e362eb4f3b

View File

@ -3,26 +3,50 @@
#include "string.hh" #include "string.hh"
#if 0 #ifdef KAK_USE_STDREGEX
#include <regex> #include <regex>
namespace kak_regex_ns = std;
#else #else
#include <boost/regex.hpp> #include <boost/regex.hpp>
namespace kak_regex_ns = boost;
#endif #endif
namespace Kakoune 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<typename Iterator> template<typename Iterator>
using RegexIterator = kak_regex_ns::regex_iterator<Iterator>; 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<typename Iterator> template<typename Iterator>
using MatchResults = kak_regex_ns::match_results<Iterator>; using RegexIterator = regex_ns::regex_iterator<Iterator>;
using RegexError = kak_regex_ns::regex_error; template<typename Iterator>
using MatchResults = regex_ns::match_results<Iterator>;
using RegexError = regex_ns::regex_error;
String option_to_string(const Regex& re); String option_to_string(const Regex& re);
void option_from_string(StringView str, Regex& re); void option_from_string(StringView str, Regex& re);