wrap

Wrap text into a paragraph.

The input text string s is formed into a paragraph by breaking it up into a sequence of lines, delineated by \n, such that the number of columns is not exceeded on each line. The last line is terminated with a \n.

S
wrap
(
S
)
(
S s
,
in size_t columns = 80
,
S firstindent = null
,
S indent = null
,
in size_t tabsize = 8
)

Parameters

s S

text string to be wrapped

columns size_t

maximum number of columns in the paragraph

firstindent S

string used to indent first line of the paragraph

indent S

string to use to indent following lines of the paragraph

tabsize size_t

column spacing of tabs in firstindent[] and indent[]

Return Value

Type: S

resulting paragraph as an allocated string

Examples

assert(wrap("a short string", 7) == "a short\nstring\n");

// wrap will not break inside of a word, but at the next space
assert(wrap("a short string", 4) == "a\nshort\nstring\n");

assert(wrap("a short string", 7, "\t") == "\ta\nshort\nstring\n");
assert(wrap("a short string", 7, "\t", "    ") == "\ta\n    short\n    string\n");

Meta