Add Example code to Documentation comment of wordWrap proc. (#10146)
This commit is contained in:
parent
7c90e22ddd
commit
e7fa8f3443
1 changed files with 5 additions and 0 deletions
|
|
@ -24,6 +24,11 @@ proc wrapWords*(s: string, maxLineWidth = 80,
|
||||||
seps: set[char] = Whitespace,
|
seps: set[char] = Whitespace,
|
||||||
newLine = "\n"): string {.noSideEffect.} =
|
newLine = "\n"): string {.noSideEffect.} =
|
||||||
## Word wraps `s`.
|
## Word wraps `s`.
|
||||||
|
runnableExamples:
|
||||||
|
doAssert "12345678901234567890".wrapWords() == "12345678901234567890"
|
||||||
|
doAssert "123456789012345678901234567890".wrapWords(20) == "12345678901234567890\n1234567890"
|
||||||
|
doAssert "Hello Bob. Hello John.".wrapWords(13, false) == "Hello Bob.\nHello John."
|
||||||
|
doAssert "Hello Bob. Hello John.".wrapWords(13, true, {';'}) == "Hello Bob. He\nllo John."
|
||||||
result = newStringOfCap(s.len + s.len shr 6)
|
result = newStringOfCap(s.len + s.len shr 6)
|
||||||
var spaceLeft = maxLineWidth
|
var spaceLeft = maxLineWidth
|
||||||
var lastSep = ""
|
var lastSep = ""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue