Skip to main content

wrap

Function wrap 

Source
pub fn wrap(text: &str, max: u16) -> Vec<String>
Expand description

Splits text into lines no wider than max cells.

Explicit newlines are kept, words move to the next line whole when they fit on it (with the punctuation attached to them, so a comma never starts a line), and words longer than a line are broken between grapheme clusters; the punctuation closing such a word breaks off with the character before it, so . or ) never starts a line alone either. Spaces at a break are dropped; no-break spaces (U+00A0, U+202F, U+2007) are part of the word.

Chinese and Japanese, written without spaces, may break between any two ideographs or kana, except that closing punctuation ( ), the long vowel mark and small kana never start a line and opening brackets ( ) never end one. Only a run of such marks wider than the line itself breaks the rule.