summaryrefslogtreecommitdiff
path: root/src/regex.cc
blob: e9d24be7de7298422cf7e32a56cc42f14af8d989 (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
31
32
33
34
#include "regex.hh"
#include "string_utils.hh"

namespace Kakoune
{

Regex::Regex(StringView re, RegexCompileFlags flags)
    : m_impl{new Impl{}},
      m_str{re.str()}
{
    static_cast<CompiledRegex&>(*m_impl) = compile_regex(re, flags);
}

int Regex::named_capture_index(StringView name) const
{
    for (auto capture : m_impl->named_captures)
    {
        if (capture.name == name)
            return capture.index;
    }
    return -1;
}

String option_to_string(const Regex& re, Quoting quoting)
{
    return option_to_string(re.str(), quoting);
}

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

}