summary refs log tree commit diff
path: root/lib/strings.nix
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2014-10-04 17:02:29 +0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2014-10-05 01:10:06 +0200
commit6c2bf141cf87d62cc8e79a155b12d3382dd10558 (patch)
tree3ffd8624cea5fba46d1574dd5a928f78158246ca /lib/strings.nix
parent65242d4a744f818e0ca459e711793fa9c2b55238 (diff)
downloadnixpkgs-6c2bf141cf87d62cc8e79a155b12d3382dd10558.tar
nixpkgs-6c2bf141cf87d62cc8e79a155b12d3382dd10558.tar.gz
nixpkgs-6c2bf141cf87d62cc8e79a155b12d3382dd10558.tar.bz2
nixpkgs-6c2bf141cf87d62cc8e79a155b12d3382dd10558.tar.lz
nixpkgs-6c2bf141cf87d62cc8e79a155b12d3382dd10558.tar.xz
nixpkgs-6c2bf141cf87d62cc8e79a155b12d3382dd10558.tar.zst
nixpkgs-6c2bf141cf87d62cc8e79a155b12d3382dd10558.zip
lib: Use arithmetic operators rather than builtins.add etc.
Diffstat (limited to 'lib/strings.nix')
-rw-r--r--lib/strings.nix16
1 files changed, 8 insertions, 8 deletions
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