various bugfixes for generics; added generic sort proc

This commit is contained in:
Araq 2011-03-03 02:01:22 +01:00
commit e424e13bd9
18 changed files with 392 additions and 113 deletions

View file

@ -97,14 +97,15 @@ proc normalize*(s: string): string {.noSideEffect, procvar,
add result, s[i]
proc cmpIgnoreCase*(a, b: string): int {.noSideEffect,
rtl, extern: "nsuCmpIgnoreCase".} =
rtl, extern: "nsuCmpIgnoreCase", procvar.} =
## Compares two strings in a case insensitive manner. Returns:
##
## | 0 iff a == b
## | < 0 iff a < b
## | > 0 iff a > b
var i = 0
while i < a.len and i < b.len:
var i = 0
var m = min(a.len, b.len)
while i < m:
result = ord(toLower(a[i])) - ord(toLower(b[i]))
if result != 0: return
inc(i)
@ -114,7 +115,7 @@ proc cmpIgnoreCase*(a, b: string): int {.noSideEffect,
# thus we compile without checks here
proc cmpIgnoreStyle*(a, b: string): int {.noSideEffect,
rtl, extern: "nsuCmpIgnoreStyle".} =
rtl, extern: "nsuCmpIgnoreStyle", procvar.} =
## Compares two strings normalized (i.e. case and
## underscores do not matter). Returns:
##