2014-10-13 14:12:33 +02:00
|
|
|
#include "regex.hh"
|
|
|
|
|
2017-10-09 08:37:43 +02:00
|
|
|
#ifdef REGEX_CHECK_WITH_BOOST
|
2017-10-02 08:59:04 +02:00
|
|
|
#include "buffer_utils.hh"
|
2017-10-09 08:37:43 +02:00
|
|
|
#endif
|
2014-10-13 14:12:33 +02:00
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2017-10-09 08:37:43 +02:00
|
|
|
#ifdef REGEX_CHECK_WITH_BOOST
|
2016-05-10 10:12:30 +02:00
|
|
|
using Utf8It = RegexUtf8It<const char*>;
|
|
|
|
|
2017-10-09 08:04:14 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-10-09 08:37:43 +02:00
|
|
|
void regex_mismatch(const Regex& re)
|
|
|
|
{
|
|
|
|
write_to_debug_buffer(format("regex mismatch for '{}'", re.str()));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-10-09 08:04:14 +02:00
|
|
|
Regex::Regex(StringView re, RegexCompileFlags flags) try
|
|
|
|
: m_impl{new CompiledRegex{compile_regex(re, flags)}},
|
2017-10-09 08:37:43 +02:00
|
|
|
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()); }
|
2016-05-10 10:12:30 +02:00
|
|
|
|
2014-10-13 14:12:33 +02:00
|
|
|
String option_to_string(const Regex& re)
|
|
|
|
{
|
2016-02-05 00:52:06 +01:00
|
|
|
return re.str();
|
2014-10-13 14:12:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void option_from_string(StringView str, Regex& re)
|
|
|
|
{
|
2015-07-25 12:15:03 +02:00
|
|
|
re = Regex{str};
|
2014-10-13 14:12:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|