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

#include "strings.hh"

#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));
}

}