Skip to content

Commit

Permalink
lib.strings.trimWith: Refactor scoping
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
adisbladis committed Sep 2, 2024
1 parent 4b6c89a commit 8a20781
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/strings.nix
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,6 @@ rec {
start ? false,
end ? false,
}:
s:
let
# Define our own whitespace character class instead of using
# `[:space:]`, which is not well-defined.
Expand All @@ -425,12 +424,14 @@ rec {
"(.*[^${chars}])[${chars}]*"
else
"(.*)";

in
s:
let
# If the string was empty or entirely whitespace,
# then the regex may not match and `res` will be `null`.
res = match regex s;
in
optionalString (res != null) (head res);
optionalString (res != null) (head res);

/**
Construct a Unix-style, colon-separated search path consisting of
Expand Down

0 comments on commit 8a20781

Please sign in to comment.