diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2012-03-19 18:04:47 +0000 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2012-03-19 18:04:47 +0000 |
commit | 6b4cd6673ad1c7b7203002040ccdbacec818135a (patch) | |
tree | bff003b363018b0be36d197f9e691fa0389e34ae /pkgs/lib/strings.nix | |
parent | af2da39a04a0577671cd3bc0cae01e73c2c889ca (diff) | |
download | nixpkgs-6b4cd6673ad1c7b7203002040ccdbacec818135a.tar nixpkgs-6b4cd6673ad1c7b7203002040ccdbacec818135a.tar.gz nixpkgs-6b4cd6673ad1c7b7203002040ccdbacec818135a.tar.bz2 nixpkgs-6b4cd6673ad1c7b7203002040ccdbacec818135a.tar.lz nixpkgs-6b4cd6673ad1c7b7203002040ccdbacec818135a.tar.xz nixpkgs-6b4cd6673ad1c7b7203002040ccdbacec818135a.tar.zst nixpkgs-6b4cd6673ad1c7b7203002040ccdbacec818135a.zip |
* Add a utility function "versionOlder" to compare two version
strings. svn path=/nixpkgs/trunk/; revision=33267
Diffstat (limited to 'pkgs/lib/strings.nix')
-rw-r--r-- | pkgs/lib/strings.nix | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/pkgs/lib/strings.nix b/pkgs/lib/strings.nix index 73520a949c1..8f918acf7b2 100644 --- a/pkgs/lib/strings.nix +++ b/pkgs/lib/strings.nix @@ -82,15 +82,18 @@ rec { map f (stringToCharacters s) ); + # same as vim escape function. # Each character contained in list is prefixed by "\" escape = list : string : stringAsChars (c: if lib.elem c list then "\\${c}" else c) string; + # still ugly slow. But more correct now # [] for zsh escapeShellArg = lib.escape (stringToCharacters "\\ ';$`()|<>\t*[]"); + # replace characters by their substitutes. This function is equivalent to # the `tr' command except that one character can be replace by multiple # ones. e.g., @@ -105,10 +108,12 @@ rec { in stringAsChars subst s; + # Compares strings not requiring context equality # Obviously, a workaround but works on all Nix versions eqStrings = a: b: (a+(substring 0 0 b)) == ((substring 0 0 a)+b); + # Cut a string with a separator and produces a list of strings which were # separated by this separator. e.g., # `splitString "." "foo.bar.baz"' returns ["foo" "bar" "baz"]. @@ -133,6 +138,7 @@ rec { in recurse 0 0; + # return the suffix of the second argument if the first argument match its # prefix. e.g., # `removePrefix "foo." "foo.bar.baz"' returns "bar.baz". @@ -146,6 +152,13 @@ rec { else s; + + # Why do we need this if we have baseNameOf? basename = s: lib.last (splitString "/" s); + + # Return true iff string v1 denotes a version older than v2. + versionOlder = v1: v2: builtins.compareVersions v2 v1 == 1; + + } |