fixes #9800 (#9804) [backport]

* fixes #9800
* add tests for #9800
This commit is contained in:
pgkos 2018-11-26 18:59:24 +01:00 • committed by Andreas Rumpf
commit 518c72e57a

View file

@ -1941,9 +1941,9 @@ proc strip*(s: string, leading = true, trailing = true,
e_i = l_i - 1 e_i = l_i - 1
break break
dec(i) dec(i)
let newLen = e_i - s_i let newLen = e_i - s_i + 1
result = newStringOfCap(newLen) result = newStringOfCap(newLen)
if e_i > s_i: if newLen > 0:
result.add s[s_i .. e_i] result.add s[s_i .. e_i]
proc repeat*(c: Rune, count: Natural): string {.noSideEffect, proc repeat*(c: Rune, count: Natural): string {.noSideEffect,
@ -2161,6 +2161,9 @@ when isMainModule:
doAssert s.split(' '.Rune, maxsplit = 1) == @["", "this is an example "] doAssert s.split(' '.Rune, maxsplit = 1) == @["", "this is an example "]
block stripTests: block stripTests:
doAssert(strip("") == "")
doAssert(strip(" ") == "")
doAssert(strip("y") == "y")
doAssert(strip(" foofoofoo ") == "foofoofoo") doAssert(strip(" foofoofoo ") == "foofoofoo")
doAssert(strip("sfoofoofoos", runes = ['s'.Rune]) == "foofoofoo") doAssert(strip("sfoofoofoos", runes = ['s'.Rune]) == "foofoofoo")