mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-13 05:05:29 +03:00
lib.strings: Add normalizePath
dedupes extranous /'s in filepaths Co-authored-by: Daniel Olsen <daniel.olsen99@gmail.com>
This commit is contained in:
parent
4c420ee485
commit
4284ac9dfb
1 changed files with 10 additions and 0 deletions
|
@ -185,6 +185,16 @@ rec {
|
||||||
*/
|
*/
|
||||||
makeBinPath = makeSearchPathOutput "bin" "bin";
|
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
|
/* Depending on the boolean `cond', return either the given string
|
||||||
or the empty string. Useful to concatenate against a bigger string.
|
or the empty string. Useful to concatenate against a bigger string.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue