wrap

fun String.wrap(maxLineLength: Int): String

Word wraps this string so that no line exceeds maxLineLength characters where possible.

Existing line breaks are kept as breaks and normalized to \n. Words within a line are joined by single spaces in the output, so runs of spaces and tabs collapse. A word longer than maxLineLength is placed on a line of its own without being broken. Returns this string unchanged when maxLineLength is zero or negative.