aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/regex.cc
blob: a12d135506430d18838e26722e272a4c638e3004 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <string>
#include <regex>

// Declared as extern in precompiled-headers.hh
template class std::basic_regex<char>;

namespace nix::regex {
std::string quoteRegexChars(const std::string & raw)
{
    static auto specialRegex = std::regex(R"([.^$\\*+?()\[\]{}|])");
    return std::regex_replace(raw, specialRegex, R"(\$&)");
}

std::regex storePathRegex(const std::string & storeDir)
{
    return std::regex(quoteRegexChars(storeDir) + R"(/[0-9a-z]+[0-9a-zA-Z\+\-\._\?=]*)");
}

}