Remove eqStrings

It's no longer needed. Also clean up some comments.
This commit is contained in:
Eelco Dolstra 2015-07-24 15:48:29 +02:00
parent 9cfd128a42
commit 2d9885db9e
1 changed files with 14 additions and 22 deletions

View File

@ -65,13 +65,13 @@ rec {
# Determine whether a string has given prefix/suffix. # Determine whether a string has given prefix/suffix.
hasPrefix = pref: str: hasPrefix = pref: str:
eqStrings (substring 0 (stringLength pref) str) pref; substring 0 (stringLength pref) str == pref;
hasSuffix = suff: str: hasSuffix = suff: str:
let let
lenStr = stringLength str; lenStr = stringLength str;
lenSuff = stringLength suff; lenSuff = stringLength suff;
in lenStr >= lenSuff && 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). # Convert a string to a list of characters (i.e. singleton strings).
@ -102,10 +102,7 @@ rec {
escapeShellArg = lib.escape (stringToCharacters "\\ ';$`()|<>\t*[]"); escapeShellArg = lib.escape (stringToCharacters "\\ ';$`()|<>\t*[]");
# replace characters by their substitutes. This function is equivalent to # Obsolete - use replaceStrings instead.
# the `tr' command except that one character can be replace by multiple
# ones. e.g.,
# replaceChars ["<" ">"] ["&lt;" "&gt;"] "<foo>" returns "&lt;foo&gt;".
replaceChars = builtins.replaceStrings or ( replaceChars = builtins.replaceStrings or (
del: new: s: del: new: s:
let let
@ -131,11 +128,6 @@ rec {
addContextFrom = a: b: substring 0 0 a + b; 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 # Cut a string with a separator and produces a list of strings which were
# separated by this separator. e.g., # separated by this separator. e.g.,
# `splitString "." "foo.bar.baz"' returns ["foo" "bar" "baz"]. # `splitString "." "foo.bar.baz"' returns ["foo" "bar" "baz"].
@ -181,7 +173,7 @@ rec {
sufLen = stringLength suf; sufLen = stringLength suf;
sLen = stringLength s; sLen = stringLength s;
in 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 substring 0 (sLen - sufLen) s
else else
s; s;
@ -200,14 +192,13 @@ rec {
# Extract name with version from URL. Ask for separator which is # Extract name with version from URL. Ask for separator which is
# supposed to start extension # supposed to start extension.
nameFromURL = url: sep: let nameFromURL = url: sep:
components = splitString "/" url; let
filename = lib.last components; components = splitString "/" url;
name = builtins.head (splitString sep filename); filename = lib.last components;
in name = builtins.head (splitString sep filename);
assert ! eqStrings name filename; in assert name != filename; name;
name;
# Create an --{enable,disable}-<feat> string that can be passed to # Create an --{enable,disable}-<feat> string that can be passed to
@ -215,7 +206,8 @@ rec {
enableFeature = enable: feat: "--${if enable then "enable" else "disable"}-${feat}"; 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: fixedWidthString = width: filler: str:
let let
strw = lib.stringLength str; strw = lib.stringLength str;
@ -225,6 +217,6 @@ rec {
if strw == width then str else filler + fixedWidthString reqWidth filler str; 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); fixedWidthNumber = width: n: fixedWidthString width "0" (toString n);
} }