Skip to content

Commit ae0b270

Browse files
dschogitster
authored andcommitted
print_wrapped_text(): allow hard newlines
print_wrapped_text() will insert its own newlines. Up until now, if the text passed to it contained newlines, they would not be handled properly (the wrapping got confused after that). The strategy is to replace a single new-line with a space, but keep double new-lines so that already-wrapped text with empty lines between paragraphs will be handled properly. However, single new-line characters are only handled this way if the character after it is an alphanumeric character, as per Linus' suggestion. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent e79999b commit ae0b270

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

utf8.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,20 +310,34 @@ int print_wrapped_text(const char *text, int indent, int indent2, int width)
310310
if (!c || isspace(c)) {
311311
if (w < width || !space) {
312312
const char *start = bol;
313+
if (!c && text == start)
314+
return w;
313315
if (space)
314316
start = space;
315317
else
316318
print_spaces(indent);
317319
fwrite(start, text - start, 1, stdout);
318320
if (!c)
319321
return w;
320-
else if (c == '\t')
321-
w |= 0x07;
322322
space = text;
323+
if (c == '\t')
324+
w |= 0x07;
325+
else if (c == '\n') {
326+
space++;
327+
if (*space == '\n') {
328+
putchar('\n');
329+
goto new_line;
330+
}
331+
else if (!isalnum(*space))
332+
goto new_line;
333+
else
334+
putchar(' ');
335+
}
323336
w++;
324337
text++;
325338
}
326339
else {
340+
new_line:
327341
putchar('\n');
328342
text = bol = space + isspace(*space);
329343
space = NULL;

0 commit comments

Comments
 (0)