kakoune/src/regex.cc

31 lines
586 B
C++
Raw Normal View History

#include "regex.hh"
#include "ranges.hh"
namespace Kakoune
{
Regex::Regex(StringView re, RegexCompileFlags flags)
2019-01-10 11:16:07 +01:00
: m_impl{new CompiledRegex{}},
m_str{re.str()}
2019-01-10 11:16:07 +01:00
{
*m_impl = compile_regex(re, flags);
}
int Regex::named_capture_index(StringView name) const
{
auto it = find_if(m_impl->named_captures, [&](auto& c) { return c.name == name; });
return it != m_impl->named_captures.end() ? it->index : -1;
}
String option_to_string(const Regex& re)
{
2016-02-05 00:52:06 +01:00
return re.str();
}
Regex option_from_string(Meta::Type<Regex>, StringView str)
{
return Regex{str};
}
}