refactor cmpIgnoreStyle and cmpIgnoreCase (#16399)
* init * support strutils * more * better * Call len once per string/cstring * Change var to let * Compare ternary on first char * More appropriate param name * fix * better * one test * impl * more efficient * minor Co-authored-by: Clyybber <darkmine956@gmail.com>
This commit is contained in:
parent
5984f7a7dd
commit
5fb56a3b2c
8 changed files with 141 additions and 147 deletions
|
|
@ -29,7 +29,7 @@ Hi Andreas! How do you feel, Rumpf?
|
|||
"""
|
||||
|
||||
import
|
||||
critbits, cstrutils, sets, strutils, tables, random, algorithm, ropes,
|
||||
critbits, sets, strutils, tables, random, algorithm, ropes,
|
||||
lists, htmlgen, xmltree, strtabs
|
||||
|
||||
|
||||
|
|
@ -177,18 +177,3 @@ block txmltree:
|
|||
])
|
||||
])
|
||||
doAssert(y.innerText == "foobar")
|
||||
|
||||
|
||||
|
||||
block tcstrutils:
|
||||
let s = cstring "abcdef"
|
||||
doAssert s.startsWith("a")
|
||||
doAssert not s.startsWith("b")
|
||||
doAssert s.endsWith("f")
|
||||
doAssert not s.endsWith("a")
|
||||
|
||||
let a = cstring "abracadabra"
|
||||
doAssert a.startsWith("abra")
|
||||
doAssert not a.startsWith("bra")
|
||||
doAssert a.endsWith("abra")
|
||||
doAssert not a.endsWith("dab")
|
||||
|
|
|
|||
30
tests/stdlib/tcstrutils.nim
Normal file
30
tests/stdlib/tcstrutils.nim
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
discard """
|
||||
targets: "c cpp js"
|
||||
"""
|
||||
|
||||
import cstrutils
|
||||
|
||||
|
||||
block tcstrutils:
|
||||
let s = cstring "abcdef"
|
||||
doAssert s.startsWith("a")
|
||||
doAssert not s.startsWith("b")
|
||||
doAssert s.endsWith("f")
|
||||
doAssert not s.endsWith("a")
|
||||
|
||||
let a = cstring "abracadabra"
|
||||
doAssert a.startsWith("abra")
|
||||
doAssert not a.startsWith("bra")
|
||||
doAssert a.endsWith("abra")
|
||||
doAssert not a.endsWith("dab")
|
||||
|
||||
doAssert cmpIgnoreCase(cstring "FooBar", "foobar") == 0
|
||||
doAssert cmpIgnoreCase(cstring "bar", "Foo") < 0
|
||||
doAssert cmpIgnoreCase(cstring "Foo5", "foo4") > 0
|
||||
|
||||
doAssert cmpIgnoreStyle(cstring "foo_bar", "FooBar") == 0
|
||||
doAssert cmpIgnoreStyle(cstring "foo_bar_5", "FooBar4") > 0
|
||||
|
||||
doAssert cmpIgnoreCase(cstring "", cstring "") == 0
|
||||
doAssert cmpIgnoreCase(cstring "", cstring "Hello") < 0
|
||||
doAssert cmpIgnoreCase(cstring "wind", cstring "") > 0
|
||||
|
|
@ -38,7 +38,7 @@ true
|
|||
"""
|
||||
|
||||
import
|
||||
critbits, cstrutils, sets, strutils, tables, random, algorithm, re, ropes,
|
||||
critbits, sets, strutils, tables, random, algorithm, re, ropes,
|
||||
segfaults, lists, parsesql, streams, os, htmlgen, xmltree, strtabs
|
||||
|
||||
|
||||
|
|
@ -245,24 +245,3 @@ block txmltree:
|
|||
])
|
||||
])
|
||||
doAssert(y.innerText == "foobar")
|
||||
|
||||
|
||||
block tcstrutils:
|
||||
let s = cstring "abcdef"
|
||||
doAssert s.startsWith("a")
|
||||
doAssert not s.startsWith("b")
|
||||
doAssert s.endsWith("f")
|
||||
doAssert not s.endsWith("a")
|
||||
|
||||
let a = cstring "abracadabra"
|
||||
doAssert a.startsWith("abra")
|
||||
doAssert not a.startsWith("bra")
|
||||
doAssert a.endsWith("abra")
|
||||
doAssert not a.endsWith("dab")
|
||||
|
||||
doAssert cmpIgnoreCase(cstring "FooBar", "foobar") == 0
|
||||
doAssert cmpIgnoreCase(cstring "bar", "Foo") < 0
|
||||
doAssert cmpIgnoreCase(cstring "Foo5", "foo4") > 0
|
||||
|
||||
doAssert cmpIgnoreStyle(cstring "foo_bar", "FooBar") == 0
|
||||
doAssert cmpIgnoreStyle(cstring "foo_bar_5", "FooBar4") > 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue