summaryrefslogtreecommitdiff
path: root/src/regex.cc
blob: b80da6d4b2a72a3a30b2a67a231395ad67e9b077 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "regex.hh"
#include "ranges.hh"

namespace Kakoune
{

Regex::Regex(StringView re, RegexCompileFlags flags)
    : m_impl{new CompiledRegex{}},
      m_str{re.str()}
{
    *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)
{
    return re.str();
}

Regex option_from_string(Meta::Type<Regex>, StringView str)
{
    return Regex{str};
}

}