Merge pull request #4282 from abudden/4252-startsWithChar
Added startsWith/endsWith implementations for character prefix/suffix…
This commit is contained in:
commit
c1a553a2a9
1 changed files with 16 additions and 0 deletions
|
|
@ -862,6 +862,10 @@ proc startsWith*(s, prefix: string): bool {.noSideEffect,
|
||||||
if s[i] != prefix[i]: return false
|
if s[i] != prefix[i]: return false
|
||||||
inc(i)
|
inc(i)
|
||||||
|
|
||||||
|
proc startsWith*(s: string, prefix: char): bool {.noSideEffect, inline.} =
|
||||||
|
## Returns true iff ``s`` starts with ``prefix``.
|
||||||
|
result = s[0] == prefix
|
||||||
|
|
||||||
proc endsWith*(s, suffix: string): bool {.noSideEffect,
|
proc endsWith*(s, suffix: string): bool {.noSideEffect,
|
||||||
rtl, extern: "nsuEndsWith".} =
|
rtl, extern: "nsuEndsWith".} =
|
||||||
## Returns true iff ``s`` ends with ``suffix``.
|
## Returns true iff ``s`` ends with ``suffix``.
|
||||||
|
|
@ -874,6 +878,10 @@ proc endsWith*(s, suffix: string): bool {.noSideEffect,
|
||||||
inc(i)
|
inc(i)
|
||||||
if suffix[i] == '\0': return true
|
if suffix[i] == '\0': return true
|
||||||
|
|
||||||
|
proc endsWith*(s: string, suffix: char): bool {.noSideEffect, inline.} =
|
||||||
|
## Returns true iff ``s`` ends with ``suffix``.
|
||||||
|
result = s[s.high] == suffix
|
||||||
|
|
||||||
proc continuesWith*(s, substr: string, start: Natural): bool {.noSideEffect,
|
proc continuesWith*(s, substr: string, start: Natural): bool {.noSideEffect,
|
||||||
rtl, extern: "nsuContinuesWith".} =
|
rtl, extern: "nsuContinuesWith".} =
|
||||||
## Returns true iff ``s`` continues with ``substr`` at position ``start``.
|
## Returns true iff ``s`` continues with ``substr`` at position ``start``.
|
||||||
|
|
@ -2029,4 +2037,12 @@ bar
|
||||||
# Don't use SI prefix as number is too small
|
# Don't use SI prefix as number is too small
|
||||||
doAssert formatEng(3.1e-25, siPrefix=true, unit="A") == "310e-27 A"
|
doAssert formatEng(3.1e-25, siPrefix=true, unit="A") == "310e-27 A"
|
||||||
|
|
||||||
|
block: # startsWith / endsWith char tests
|
||||||
|
var s = "abcdef"
|
||||||
|
doAssert s.startsWith('a')
|
||||||
|
doAssert s.startsWith('b') == false
|
||||||
|
doAssert s.endsWith('f')
|
||||||
|
doAssert s.endsWith('a') == false
|
||||||
|
doAssert s.endsWith('\0') == false
|
||||||
|
|
||||||
#echo("strutils tests passed")
|
#echo("strutils tests passed")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue