From 2d9885db9e8b790ba2f8fc69b50a073260822a4f Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 24 Jul 2015 15:48:29 +0200 Subject: Remove eqStrings It's no longer needed. Also clean up some comments. --- lib/strings.nix | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) (limited to 'lib/strings.nix') diff --git a/lib/strings.nix b/lib/strings.nix index 6eb2652280c..c5af703e4e1 100644 --- a/lib/strings.nix +++ b/lib/strings.nix @@ -65,13 +65,13 @@ rec { # Determine whether a string has given prefix/suffix. hasPrefix = pref: str: - eqStrings (substring 0 (stringLength pref) str) pref; + substring 0 (stringLength pref) str == pref; hasSuffix = suff: str: let lenStr = stringLength str; lenSuff = stringLength suff; in lenStr >= lenSuff && - eqStrings (substring (lenStr - lenSuff) lenStr str) suff; + substring (lenStr - lenSuff) lenStr str == suff; # Convert a string to a list of characters (i.e. singleton strings). @@ -102,10 +102,7 @@ rec { 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., - # replaceChars ["<" ">"] ["<" ">"] "" returns "<foo>". + # Obsolete - use replaceStrings instead. replaceChars = builtins.replaceStrings or ( del: new: s: let @@ -131,11 +128,6 @@ rec { addContextFrom = a: b: substring 0 0 a + b; - # Compares strings not requiring context equality - # Obviously, a workaround but works on all Nix versions. - eqStrings = a: b: addContextFrom b a == addContextFrom 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"]. @@ -181,7 +173,7 @@ rec { sufLen = stringLength suf; sLen = stringLength s; in - if sufLen <= sLen && eqStrings suf (substring (sLen - sufLen) sufLen s) then + if sufLen <= sLen && suf == substring (sLen - sufLen) sufLen s then substring 0 (sLen - sufLen) s else s; @@ -200,14 +192,13 @@ rec { # Extract name with version from URL. Ask for separator which is - # supposed to start extension - nameFromURL = url: sep: let - components = splitString "/" url; - filename = lib.last components; - name = builtins.head (splitString sep filename); - in - assert ! eqStrings name filename; - name; + # supposed to start extension. + nameFromURL = url: sep: + let + components = splitString "/" url; + filename = lib.last components; + name = builtins.head (splitString sep filename); + in assert name != filename; name; # Create an --{enable,disable}- string that can be passed to @@ -215,7 +206,8 @@ rec { enableFeature = enable: feat: "--${if enable then "enable" else "disable"}-${feat}"; - # Create a fixed width string with additional prefix to match required width + # Create a fixed width string with additional prefix to match + # required width. fixedWidthString = width: filler: str: let strw = lib.stringLength str; @@ -225,6 +217,6 @@ rec { if strw == width then str else filler + fixedWidthString reqWidth filler str; - # Format a number adding leading zeroes up to fixed width + # Format a number adding leading zeroes up to fixed width. fixedWidthNumber = width: n: fixedWidthString width "0" (toString n); } -- cgit 1.4.1