From 3c2124c471814ba196e82e077ac3235c79430b07 Mon Sep 17 00:00:00 2001 From: Naïm Favier Date: Fri, 2 Dec 2022 11:57:20 +0100 Subject: lib/strings: simplify `splitString` There's no need to use `unsafeDiscardStringContext` since https://github.com/NixOS/nix/commit/ee7fe64c0ac00f2be11604a2a6509eb86dc19f0a (Nix 1.8). Also the separator can't have a context since `builtins.split` would fail, so we can assume it doesn't. --- lib/strings.nix | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/strings.nix b/lib/strings.nix index b5f5a4d9060..dd4796a15f3 100644 --- a/lib/strings.nix +++ b/lib/strings.nix @@ -510,7 +510,7 @@ rec { toUpper = replaceChars lowerChars upperChars; /* Appends string context from another string. This is an implementation - detail of Nix. + detail of Nix and should be used carefully. Strings in Nix carry an invisible `context` which is a list of strings representing store paths. If the string is later used in a derivation @@ -533,13 +533,11 @@ rec { splitString "/" "/usr/local/bin" => [ "" "usr" "local" "bin" ] */ - splitString = _sep: _s: + splitString = sep: s: let - sep = builtins.unsafeDiscardStringContext _sep; - s = builtins.unsafeDiscardStringContext _s; - splits = builtins.filter builtins.isString (builtins.split (escapeRegex sep) s); + splits = builtins.filter builtins.isString (builtins.split (escapeRegex (toString sep)) (toString s)); in - map (v: addContextFrom _sep (addContextFrom _s v)) splits; + map (addContextFrom s) splits; /* Return a string without the specified prefix, if the prefix matches. -- cgit 1.4.1