mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-09-11 15:08:33 +01:00
lib.strings.trimWith: Refactor scoping
I wanted to use this instead of [my ownimplementation](https://github.com/nix-community/pyproject.nix/blob/65d4134/lib/util.nix#L18-L23) and got a small performance regression.
This commit is contained in:
parent
4b6c89a670
commit
8a20781579
|
@ -408,7 +408,6 @@ rec {
|
||||||
start ? false,
|
start ? false,
|
||||||
end ? false,
|
end ? false,
|
||||||
}:
|
}:
|
||||||
s:
|
|
||||||
let
|
let
|
||||||
# Define our own whitespace character class instead of using
|
# Define our own whitespace character class instead of using
|
||||||
# `[:space:]`, which is not well-defined.
|
# `[:space:]`, which is not well-defined.
|
||||||
|
@ -425,12 +424,14 @@ rec {
|
||||||
"(.*[^${chars}])[${chars}]*"
|
"(.*[^${chars}])[${chars}]*"
|
||||||
else
|
else
|
||||||
"(.*)";
|
"(.*)";
|
||||||
|
in
|
||||||
|
s:
|
||||||
|
let
|
||||||
# If the string was empty or entirely whitespace,
|
# If the string was empty or entirely whitespace,
|
||||||
# then the regex may not match and `res` will be `null`.
|
# then the regex may not match and `res` will be `null`.
|
||||||
res = match regex s;
|
res = match regex s;
|
||||||
in
|
in
|
||||||
optionalString (res != null) (head res);
|
optionalString (res != null) (head res);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Construct a Unix-style, colon-separated search path consisting of
|
Construct a Unix-style, colon-separated search path consisting of
|
||||||
|
|
Loading…
Reference in a new issue