1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-24 22:11:15 +02:00
This commit is contained in:
Damien Diederen 2025-06-20 18:54:24 -04:00 committed by GitHub
commit 4244736326
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 27 additions and 6 deletions

View file

@ -41,10 +41,10 @@ namespace nix {
* Miscellaneous * Miscellaneous
*************************************************************/ *************************************************************/
static inline Value * mkString(EvalState & state, const std::csub_match & match) static inline Value * mkString(EvalState & state, const std::csub_match & match, const NixStringContext & context)
{ {
Value * v = state.allocValue(); Value * v = state.allocValue();
v->mkString({match.first, match.second}); v->mkString({match.first, match.second}, context);
return v; return v;
} }
@ -4395,7 +4395,7 @@ void prim_match(EvalState & state, const PosIdx pos, Value * * args, Value & v)
if (!match[i + 1].matched) if (!match[i + 1].matched)
v2 = &state.vNull; v2 = &state.vNull;
else else
v2 = mkString(state, match[i + 1]); v2 = mkString(state, match[i + 1], context);
v.mkList(list); v.mkList(list);
} catch (std::regex_error & e) { } catch (std::regex_error & e) {
@ -4479,7 +4479,7 @@ void prim_split(EvalState & state, const PosIdx pos, Value * * args, Value & v)
const auto & match = *i; const auto & match = *i;
// Add a string for non-matched characters. // Add a string for non-matched characters.
list[idx++] = mkString(state, match.prefix()); list[idx++] = mkString(state, match.prefix(), context);
// Add a list for matched substrings. // Add a list for matched substrings.
const size_t slen = match.size() - 1; const size_t slen = match.size() - 1;
@ -4490,14 +4490,14 @@ void prim_split(EvalState & state, const PosIdx pos, Value * * args, Value & v)
if (!match[si + 1].matched) if (!match[si + 1].matched)
v2 = &state.vNull; v2 = &state.vNull;
else else
v2 = mkString(state, match[si + 1]); v2 = mkString(state, match[si + 1], context);
} }
(list[idx++] = state.allocValue())->mkList(list2); (list[idx++] = state.allocValue())->mkList(list2);
// Add a string for non-matched suffix characters. // Add a string for non-matched suffix characters.
if (idx == 2 * len) if (idx == 2 * len)
list[idx++] = mkString(state, match.suffix()); list[idx++] = mkString(state, match.suffix(), context);
} }
assert(idx == 2 * len + 1); assert(idx == 2 * len + 1);

View file

@ -0,0 +1 @@
[ true true true ]

View file

@ -0,0 +1,20 @@
let
s = "${builtins.derivation {
name = "test";
builder = "/bin/sh";
system = "x86_64-linux";
}}";
c = builtins.getContext s;
matchRes = builtins.match ".*(-).*" s;
splitRes = builtins.split "(-)" s;
in
[
(c == builtins.getContext (builtins.head matchRes))
(c == builtins.getContext (builtins.head splitRes))
(c == builtins.getContext (builtins.head (builtins.elemAt splitRes 1)))
]