FIXUP: Removed +1 causing substr slicing to skip chars on first iteration of while loop (#7312)
This commit is contained in:
parent
551d7b7dc1
commit
67fd7a7f86
1 changed files with 6 additions and 1 deletions
|
|
@ -1250,7 +1250,7 @@ proc wordWrap*(s: string, maxLineWidth = 80,
|
||||||
if len(word) > spaceLeft:
|
if len(word) > spaceLeft:
|
||||||
if splitLongWords and len(word) > maxLineWidth:
|
if splitLongWords and len(word) > maxLineWidth:
|
||||||
result.add(substr(word, 0, spaceLeft-1))
|
result.add(substr(word, 0, spaceLeft-1))
|
||||||
var w = spaceLeft+1
|
var w = spaceLeft
|
||||||
var wordLeft = len(word) - spaceLeft
|
var wordLeft = len(word) - spaceLeft
|
||||||
while wordLeft > 0:
|
while wordLeft > 0:
|
||||||
result.add(newLine)
|
result.add(newLine)
|
||||||
|
|
@ -2514,6 +2514,11 @@ when isMainModule:
|
||||||
outp = " this is a\nlong text\n--\nmuchlongerthan10chars\nand here\nit goes"
|
outp = " this is a\nlong text\n--\nmuchlongerthan10chars\nand here\nit goes"
|
||||||
doAssert wordWrap(inp, 10, false) == outp
|
doAssert wordWrap(inp, 10, false) == outp
|
||||||
|
|
||||||
|
let
|
||||||
|
longInp = """ThisIsOneVeryLongStringWhichWeWillSplitIntoEightSeparatePartsNow"""
|
||||||
|
longOutp = "ThisIsOn\neVeryLon\ngStringW\nhichWeWi\nllSplitI\nntoEight\nSeparate\nPartsNow"
|
||||||
|
doAssert wordWrap(longInp, 8, true) == longOutp
|
||||||
|
|
||||||
doAssert formatBiggestFloat(1234.567, ffDecimal, -1) == "1234.567000"
|
doAssert formatBiggestFloat(1234.567, ffDecimal, -1) == "1234.567000"
|
||||||
doAssert formatBiggestFloat(1234.567, ffDecimal, 0) == "1235."
|
doAssert formatBiggestFloat(1234.567, ffDecimal, 0) == "1235."
|
||||||
doAssert formatBiggestFloat(1234.567, ffDecimal, 1) == "1234.6"
|
doAssert formatBiggestFloat(1234.567, ffDecimal, 1) == "1234.6"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue