std/wordwrap

  Source   Edit

This module contains an algorithm to wordwrap a Unicode string.

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