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
parent ed8b4befbf
commit 518c72e57a

View File

@@ -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")