mirror of
https://github.com/NixOS/nix
synced 2025-06-27 16:51:15 +02:00
Merge remote-tracking branch 'origin/master' into flakes
This commit is contained in:
commit
73b6d87e17
11 changed files with 93 additions and 51 deletions
|
@ -1812,19 +1812,21 @@ static void prim_hashString(EvalState & state, const Pos & pos, Value * * args,
|
|||
|
||||
/* Match a regular expression against a string and return either
|
||||
‘null’ or a list containing substring matches. */
|
||||
static void prim_match(EvalState & state, const Pos & pos, Value * * args, Value & v)
|
||||
void prim_match(EvalState & state, const Pos & pos, Value * * args, Value & v)
|
||||
{
|
||||
auto re = state.forceStringNoCtx(*args[0], pos);
|
||||
|
||||
try {
|
||||
|
||||
std::regex regex(re, std::regex::extended);
|
||||
auto regex = state.regexCache.find(re);
|
||||
if (regex == state.regexCache.end())
|
||||
regex = state.regexCache.emplace(re, std::regex(re, std::regex::extended)).first;
|
||||
|
||||
PathSet context;
|
||||
const std::string str = state.forceString(*args[1], context, pos);
|
||||
|
||||
std::smatch match;
|
||||
if (!std::regex_match(str, match, regex)) {
|
||||
if (!std::regex_match(str, match, regex->second)) {
|
||||
mkNull(v);
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue