aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/regex-combinators.hh
blob: 0b997b25ab47a3d3af01d72856c4488af498133b (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
#pragma once

#include <string_view>

namespace nix::regex {

// TODO use constexpr string building like
// https://github.com/akrzemi1/static_string/blob/master/include/ak_toolkit/static_string.hpp

static inline std::string either(std::string_view a, std::string_view b)
{
    return std::string { a } + "|" + b;
}

static inline std::string group(std::string_view a)
{
    return std::string { "(" } + a + ")";
}

static inline std::string many(std::string_view a)
{
    return std::string { "(?:" } + a + ")*";
}

static inline std::string list(std::string_view a)
{
    return std::string { a } + many(group("," + a));
}

}