From 6c2bf141cf87d62cc8e79a155b12d3382dd10558 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sat, 4 Oct 2014 17:02:29 +0200 Subject: lib: Use arithmetic operators rather than builtins.add etc. --- lib/strings.nix | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'lib/strings.nix') diff --git a/lib/strings.nix b/lib/strings.nix index 31b0f56e09b..56d990de62d 100644 --- a/lib/strings.nix +++ b/lib/strings.nix @@ -2,7 +2,7 @@ let lib = import ./default.nix; -inherit (builtins) add sub lessThan length; +inherit (builtins) length; in @@ -79,7 +79,7 @@ rec { stringToCharacters = s: let l = stringLength s; in if l == 0 then [] - else map (p: substring p 1 s) (lib.range 0 (sub l 1)); + else map (p: substring p 1 s) (lib.range 0 (l - 1)); # Manipulate a string charcater by character and replace them by strings @@ -123,7 +123,7 @@ rec { toUpper = replaceChars lowerChars upperChars; # Appends string context from another string - 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 @@ -139,18 +139,18 @@ rec { s = addContextFrom _sep _s; sepLen = stringLength sep; sLen = stringLength s; - lastSearch = sub sLen sepLen; + lastSearch = sLen - sepLen; startWithSep = startAt: substring startAt sepLen s == sep; recurse = index: startAt: - let cutUntil = i: [(substring startAt (sub i startAt) s)]; in - if lessThan index lastSearch then + let cutUntil = i: [(substring startAt (i - startAt) s)]; in + if index < lastSearch then if startWithSep index then - let restartAt = add index sepLen; in + let restartAt = index + sepLen; in cutUntil index ++ recurse restartAt restartAt else - recurse (add index 1) startAt + recurse (index + 1) startAt else cutUntil sLen; in -- cgit 1.4.1