Word wrap

Syntax

s.wrap(width [repl] [delim] [flags] [minwidth])

 

Parameters

s - str variable, containing text to wrap.

width - desired number of characters in lines. Minimum 4.

repl - string to insert in place of line breaks. Default or "": "[]" (new-line characters).

delim - delimiters. The function always breaks at spaces and tabs, even if they are not included in delim. Characters from delim are used if there are no spaces in line, or flag 4 is used.

flags:

1 before processing, join lines
2 leave spaces around new line-breaks
4 don't prefer spaces (all delimiter characters will have same priority)
0x100 delim is table of delimiters.
0x200 QM 2.3.3. Add blanks to delim.

minwidth - minimal line width. Default: 0. For example, if you set minwidth equal to width, lines will be width length, regardless of delimiters.

 

Remarks

Folds text into desired width. Lines will never be longer than width characters. Breaks at spaces, tabs and characters specified in delim. If there are no spaces or other delimiter characters in the specified width, breaks word. Breaks lines by inserting new-line characters or repl string. Trims spaces around new line-breaks.

 

Note that in Unicode mode text is interpreted as UTF-8, where non ASCII characters consist of several bytes. The function does not break a word in a middle of a multibyte character. width and minwidth always specify number of bytes.