mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-21 16:31:39 +00:00
@@ -1941,9 +1941,9 @@ proc strip*(s: string, leading = true, trailing = true,
|
||||
e_i = l_i - 1
|
||||
break
|
||||
dec(i)
|
||||
let newLen = e_i - s_i
|
||||
let newLen = e_i - s_i + 1
|
||||
result = newStringOfCap(newLen)
|
||||
if e_i > s_i:
|
||||
if newLen > 0:
|
||||
result.add s[s_i .. e_i]
|
||||
|
||||
proc repeat*(c: Rune, count: Natural): string {.noSideEffect,
|
||||
@@ -2161,6 +2161,9 @@ when isMainModule:
|
||||
doAssert s.split(' '.Rune, maxsplit = 1) == @["", "this is an example "]
|
||||
|
||||
block stripTests:
|
||||
doAssert(strip("") == "")
|
||||
doAssert(strip(" ") == "")
|
||||
doAssert(strip("y") == "y")
|
||||
doAssert(strip(" foofoofoo ") == "foofoofoo")
|
||||
doAssert(strip("sfoofoofoos", runes = ['s'.Rune]) == "foofoofoo")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user