From 0b07b47f69b0b2cf9d08eaa8d302a4472242c5c1 Mon Sep 17 00:00:00 2001
From: Andreas Rumpf <rumpf_a@web.de>
Date: Sun, 14 Feb 2010 19:10:23 +0100
Subject: BUGFIX: strutils.cmpIgnoreCase

---
 lib/pure/strutils.nim | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

(limited to 'lib/pure/strutils.nim')

diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim
index 2fd2aaeef..724d00ee9 100644
--- a/lib/pure/strutils.nim
+++ b/lib/pure/strutils.nim
@@ -482,12 +482,13 @@ proc `%`(formatstr: string, a: openarray[string]): string =
   addf(result, formatstr, a)
 
 proc cmpIgnoreCase(a, b: string): int =
-  # makes usage of the fact that strings are zero-terminated
-  for i in 0..len(a)-1:
-    var aa = toLower(a[i])
-    var bb = toLower(b[i])
-    result = ord(aa) - ord(bb)
-    if result != 0: break
+  var i = 0
+  while i < a.len and i < b.len:
+    result = ord(toLower(a[i])) - ord(toLower(b[i]))
+    if result != 0: return
+    inc(i)
+  result = a.len - b.len
+
 
 {.push checks: off, line_trace: off .} # this is a hot-spot in the compiler!
                                        # thus we compile without checks here
-- 
cgit 1.4.1-2-gfad0