diff options
author | ajs124 <git@ajs124.de> | 2022-06-12 14:09:42 +0200 |
---|---|---|
committer | Daniel Olsen <daniel.olsen99@gmail.com> | 2022-10-20 20:12:15 +0200 |
commit | 4284ac9dfb118097eb9e2d5f27e11208f2e715e4 (patch) | |
tree | 2abceb7064a3fe65cfd444a5c1cb0658f571b247 /lib | |
parent | 4c420ee4854d8b0a9d0d224588f0cd033f6b4381 (diff) | |
download | nixlib-4284ac9dfb118097eb9e2d5f27e11208f2e715e4.tar nixlib-4284ac9dfb118097eb9e2d5f27e11208f2e715e4.tar.gz nixlib-4284ac9dfb118097eb9e2d5f27e11208f2e715e4.tar.bz2 nixlib-4284ac9dfb118097eb9e2d5f27e11208f2e715e4.tar.lz nixlib-4284ac9dfb118097eb9e2d5f27e11208f2e715e4.tar.xz nixlib-4284ac9dfb118097eb9e2d5f27e11208f2e715e4.tar.zst nixlib-4284ac9dfb118097eb9e2d5f27e11208f2e715e4.zip |
lib.strings: Add normalizePath
dedupes extranous /'s in filepaths Co-authored-by: Daniel Olsen <daniel.olsen99@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/strings.nix | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/strings.nix b/lib/strings.nix index b12dac54f4ff..be217cb06469 100644 --- a/lib/strings.nix +++ b/lib/strings.nix @@ -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. |