aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--degesch.c19
1 files changed, 5 insertions, 14 deletions
diff --git a/degesch.c b/degesch.c
index 52141fc..14e2c40 100644
--- a/degesch.c
+++ b/degesch.c
@@ -6794,7 +6794,7 @@ static size_t
wrap_text_for_single_line (const char *text, size_t text_len,
size_t line_len, struct str *output)
{
- int eaten = 0;
+ size_t eaten = 0;
// First try going word by word
const char *word_start;
@@ -6822,21 +6822,12 @@ wrap_text_for_single_line (const char *text, size_t text_len,
return eaten + (word_start - text);
// And if that doesn't help, cut the longest valid block of characters
- while (true)
+ for (const char *p = text; (size_t) (p - text) <= line_len; )
{
- const char *next = utf8_next (text, text_len - eaten, NULL);
- hard_assert (next);
-
- size_t char_len = next - text;
- if (char_len > line_len)
- break;
-
- str_append_data (output, text, char_len);
-
- text += char_len;
- eaten += char_len;
- line_len -= char_len;
+ eaten = p - text;
+ hard_assert ((p = utf8_next (p, text_len - eaten, NULL)));
}
+ str_append_data (output, text, eaten);
return eaten;
}