Skip to content

Commit

Permalink
lib.strings: Add normalizePath
Browse files Browse the repository at this point in the history
dedupes extranous /'s in filepaths

Co-authored-by: Daniel Olsen <[email protected]>
  • Loading branch information
ajs124 and dali99 committed Oct 20, 2022
1 parent 4c420ee commit 4284ac9
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/strings.nix
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,16 @@ rec {
*/
makeBinPath = makeSearchPathOutput "bin" "bin";

/* Normalize path, removing extranous /s
Type: normalizePath :: string -> string
Example:
normalizePath "/a//b///c/"
=> "/a/b/c/"
*/
normalizePath = s: (builtins.foldl' (x: y: if y == "/" && hasSuffix "/" x then x else x+y) "" (splitString "" s));

/* Depending on the boolean `cond', return either the given string
or the empty string. Useful to concatenate against a bigger string.
Expand Down

0 comments on commit 4284ac9

Please sign in to comment.