wordwrap

This module contains an algorithm to wordwrap a Unicode string.

Imports

strutils, unicode

Procs

proc wrapWords(s: string; maxLineWidth = 80; splitLongWords = true;
               seps: set[char] = Whitespace; newLine = "\n"): string {...}{.
    noSideEffect, raises: [], tags: [].}
Word wraps s.

Example:

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."
Source Edit

© 2006–2021 Andreas Rumpf
Licensed under the MIT License.
https://nim-lang.org/docs/wordwrap.html