Skip to main content

wrap

A word-wrap function that preserves existing line breaks. Expects that existing line breaks are posix newlines. Preserve all white space except added line breaks consume the space on which they break the line. Don't wrap long words, thus the output text may have lines longer than width.

def wrap(
text: string,
width: integer
) - > string

A word-wrap function that preserves existing line breaks. Expects that existing line breaks are posix newlines. Preserve all white space except added line breaks consume the space on which they break the line. Don't wrap long words, thus the output text may have lines longer than width.

Parameters

NameTypeDescription
textstringThe input string to be wrapped, expected to use POSIX-style newlines.
widthintegerThe maximum number of characters allowed per line before a wrap is attempted.

Returns

TypeDescription
stringThe wrapped text string with original line breaks preserved and new ones inserted at the specified width.