mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-01 17:41:17 +00:00
Merge pull request #1342 from def-/wordwrap-change
Change wordwrap to remove separators at newlines
This commit is contained in:
@@ -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".} =
|
||||
|
||||
Reference in New Issue
Block a user