diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2010-02-14 19:10:23 +0100 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2010-02-14 19:10:23 +0100 |
commit | 0b07b47f69b0b2cf9d08eaa8d302a4472242c5c1 (patch) | |
tree | 40721c5fb4c6632dbe552221dc8713e6c7df7517 /lib/pure/strutils.nim | |
parent | a6a621d8701c7b9caa4f03476563525138e5a802 (diff) | |
download | Nim-0b07b47f69b0b2cf9d08eaa8d302a4472242c5c1.tar.gz |
BUGFIX: strutils.cmpIgnoreCase
Diffstat (limited to 'lib/pure/strutils.nim')
-rw-r--r-- | lib/pure/strutils.nim | 13 |
1 files changed, 7 insertions, 6 deletions
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 |