MCPcopy Index your code
hub / github.com/git/git / strbuf_add_wrapped_text

Function strbuf_add_wrapped_text

utf8.c:277–357  ·  view source on GitHub ↗

* Wrap the text, if necessary. The variable indent is the indent for the * first line, indent2 is the indent for all other lines. * If indent is negative, assume that already -indent columns have been * consumed (and no extra indent is necessary for the first line). */

Source from the content-addressed store, hash-verified

275 * consumed (and no extra indent is necessary for the first line).
276 */
277void strbuf_add_wrapped_text(struct strbuf *buf,
278 const char *text, int indent1, int indent2, int width)
279{
280 int indent, w, assume_utf8 = 1;
281 const char *bol, *space, *start = text;
282 size_t orig_len = buf->len;
283
284 if (width <= 0) {
285 strbuf_add_indented_text(buf, text, indent1, indent2);
286 return;
287 }
288
289retry:
290 bol = text;
291 w = indent = indent1;
292 space = NULL;
293 if (indent < 0) {
294 w = -indent;
295 space = text;
296 }
297
298 for (;;) {
299 char c;
300 size_t skip;
301
302 while ((skip = display_mode_esc_sequence_len(text)))
303 text += skip;
304
305 c = *text;
306 if (!c || isspace(c)) {
307 if (w <= width || !space) {
308 const char *start = bol;
309 if (!c && text == start)
310 return;
311 if (space)
312 start = space;
313 else
314 strbuf_addchars(buf, ' ', indent);
315 strbuf_add(buf, start, text - start);
316 if (!c)
317 return;
318 space = text;
319 if (c == '\t')
320 w |= 0x07;
321 else if (c == '\n') {
322 space++;
323 if (*space == '\n') {
324 strbuf_addch(buf, '\n');
325 goto new_line;
326 }
327 else if (!isalnum(*space))
328 goto new_line;
329 else
330 strbuf_addch(buf, ' ');
331 }
332 w++;
333 text++;
334 }

Callers 3

strbuf_add_wrapped_bytesFunction · 0.85
strbuf_wrapFunction · 0.85
add_wrapped_shortlog_msgFunction · 0.85

Calls 7

strbuf_add_indented_textFunction · 0.85
strbuf_addcharsFunction · 0.85
strbuf_addFunction · 0.85
strbuf_addchFunction · 0.85
utf8_widthFunction · 0.85
strbuf_setlenFunction · 0.85

Tested by

no test coverage detected