2014-10-13 14:12:33 +02:00
|
|
|
#include "regex.hh"
|
2019-01-03 12:52:15 +01:00
|
|
|
#include "ranges.hh"
|
2023-11-12 20:50:48 +01:00
|
|
|
#include "string_utils.hh"
|
2014-10-13 14:12:33 +02:00
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2017-12-01 12:57:02 +01:00
|
|
|
Regex::Regex(StringView re, RegexCompileFlags flags)
|
2024-03-22 09:54:25 +01:00
|
|
|
: m_impl{new Impl{}},
|
2017-10-09 08:37:43 +02:00
|
|
|
m_str{re.str()}
|
2019-01-10 11:16:07 +01:00
|
|
|
{
|
2024-03-22 09:54:25 +01:00
|
|
|
static_cast<CompiledRegex&>(*m_impl) = compile_regex(re, flags);
|
2019-01-10 11:16:07 +01:00
|
|
|
}
|
2016-05-10 10:12:30 +02:00
|
|
|
|
2019-01-03 12:52:15 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-11-12 20:50:48 +01:00
|
|
|
String option_to_string(const Regex& re, Quoting quoting)
|
2014-10-13 14:12:33 +02:00
|
|
|
{
|
2023-11-12 20:50:48 +01:00
|
|
|
return option_to_string(re.str(), quoting);
|
2014-10-13 14:12:33 +02:00
|
|
|
}
|
|
|
|
|
2018-05-27 05:00:04 +02:00
|
|
|
Regex option_from_string(Meta::Type<Regex>, StringView str)
|
2014-10-13 14:12:33 +02:00
|
|
|
{
|
2018-05-27 05:00:04 +02:00
|
|
|
return Regex{str};
|
2014-10-13 14:12:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|