10 #include "fold/fold.h"
12 void fold_text(const char *text,
14 int line_cb(void *arg, const char *start, int len),
17 const char *start, *end, *sep;
18 size_t sep_bytes, len;
22 /* start, end and sep are byte-positions in the string, and should always
23 * lie on the start of a multibyte sequence */
24 start = end = sep = text;
28 memset(&ps, 0, sizeof(ps));
35 bytes = mbrtowc(&wc, end, len - (end - text), &ps);
39 /* we'll get a zero size for the nul terminator */
41 line_cb(arg, start, end - start);
46 rc = line_cb(arg, start, end - start);
47 start = sep = end += bytes;
55 /* we should have caught this in the !bytes check... */
57 line_cb(arg, start, end - start);
61 /* unprintable character? just add it to the current line */
71 /* split on a previous word boundary, if
73 rc = line_cb(arg, start, sep - start);
74 end = sep + sep_bytes;
76 /* otherwise, break the word */
77 rc = line_cb(arg, start, end - start);
84 /* record our last separator */