diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2014-07-15 19:09:24 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2014-07-15 19:09:24 +0200 |
commit | 45bf087ce72e6ad703ebd97a91f844423738b956 (patch) | |
tree | 8ce573348c7888a849da937a88ac0075597b5134 /lib | |
parent | 1e38dcbfae1588425e657b63d4a2da46cb820a50 (diff) | |
parent | 66fad123916924b42228487067eb155af830bef1 (diff) | |
download | Nim-45bf087ce72e6ad703ebd97a91f844423738b956.tar.gz |
Merge pull request #1342 from def-/wordwrap-change
Change wordwrap to remove separators at newlines
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/strutils.nim | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim index e642f6a99..51392ba50 100644 --- a/lib/pure/strutils.nim +++ b/lib/pure/strutils.nim @@ -535,7 +535,12 @@ proc wordWrap*(s: string, maxLineWidth = 80, ## word wraps `s`. result = newStringOfCap(s.len + s.len shr 6) var spaceLeft = maxLineWidth + var lastSep = "" for word, isSep in tokenize(s, seps): + if isSep: + lastSep = word + spaceLeft = spaceLeft - len(word) + continue if len(word) > spaceLeft: if splitLongWords and len(word) > maxLineWidth: result.add(substr(word, 0, spaceLeft-1)) @@ -554,7 +559,8 @@ proc wordWrap*(s: string, maxLineWidth = 80, result.add(word) else: spaceLeft = spaceLeft - len(word) - result.add(word) + result.add(lastSep & word) + lastSep.setLen(0) proc unindent*(s: string, eatAllIndent = false): string {. noSideEffect, rtl, extern: "nsuUnindent".} = |