aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-12-08 22:39:16 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2015-12-08 23:24:40 +0100
commit07201b7bdcff5612f573aee10f3caa007a9d98d5 (patch)
tree20fa1102831e5901169aadb7276373ccdc8b4fea
parent2ae916fc1a32a33cf9e576741cf9e62bc445776c (diff)
downloadxK-07201b7bdcff5612f573aee10f3caa007a9d98d5.tar.gz
xK-07201b7bdcff5612f573aee10f3caa007a9d98d5.tar.xz
xK-07201b7bdcff5612f573aee10f3caa007a9d98d5.zip
degesch: compactify word wrapping algorithm
-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;
}