mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-22 06:53:01 +00:00
lib/strings: simplify splitString
There's no need to use `unsafeDiscardStringContext` since
ee7fe64c0a
(Nix 1.8).
Also the separator can't have a context since `builtins.split` would fail, so
we can assume it doesn't.
This commit is contained in:
parent
3dc19ce82d
commit
3c2124c471
@ -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.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user