Fix cmpStrings in js mode (#7604)
This commit is contained in:
parent
6795d9931b
commit
b98cd3bf34
2 changed files with 11 additions and 2 deletions
|
|
@ -417,11 +417,11 @@ proc cmpStrings(a, b: string): int {.asmNoStackFrame, compilerProc.} =
|
||||||
if (`a` == `b`) return 0;
|
if (`a` == `b`) return 0;
|
||||||
if (!`a`) return -1;
|
if (!`a`) return -1;
|
||||||
if (!`b`) return 1;
|
if (!`b`) return 1;
|
||||||
for (var i = 0; i < `a`.length-1; ++i) {
|
for (var i = 0; i < `a`.length - 1 && i < `b`.length - 1; i++) {
|
||||||
var result = `a`[i] - `b`[i];
|
var result = `a`[i] - `b`[i];
|
||||||
if (result != 0) return result;
|
if (result != 0) return result;
|
||||||
}
|
}
|
||||||
return 0;
|
return `a`.length - `b`.length;
|
||||||
"""
|
"""
|
||||||
|
|
||||||
proc cmp(x, y: string): int =
|
proc cmp(x, y: string): int =
|
||||||
|
|
|
||||||
|
|
@ -76,3 +76,12 @@ block: # String case of
|
||||||
case s
|
case s
|
||||||
of "Привет!": discard
|
of "Привет!": discard
|
||||||
else: doAssert(false)
|
else: doAssert(false)
|
||||||
|
|
||||||
|
block: # String cmp
|
||||||
|
var a, b: string
|
||||||
|
doAssert(cmp(a, b) == 0)
|
||||||
|
doAssert(cmp("foo", "foo") == 0)
|
||||||
|
doAssert(cmp("foobar", "foo") == 3)
|
||||||
|
doAssert(cmp("foo", "foobar") == -3)
|
||||||
|
doAssert(cmp("fooz", "foog") == 19)
|
||||||
|
doAssert(cmp("foog", "fooz") == -19)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue