diff options
Diffstat (limited to 'src/gfx.cpp')
-rw-r--r-- | src/gfx.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/gfx.cpp b/src/gfx.cpp index 4ed1ea424..2599344a5 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -296,7 +296,7 @@ static int TruncateString(char *str, int maxw) if (w >= maxw) { /* string got too big... insert dotdotdot */ ddd_pos[0] = ddd_pos[1] = ddd_pos[2] = '.'; - ddd_pos[3] = 0; + ddd_pos[3] = '\0'; return ddd_w; } } else { @@ -440,7 +440,7 @@ uint32 FormatStringLinebreaks(char *str, int maxw) for (;;) { WChar c = Utf8Consume((const char **)&str); /* whitespace is where we will insert the line-break */ - if (c == ' ') last_space = str; + if (IsWhitespace(c)) last_space = str; if (IsPrintable(c)) { w += GetCharacterWidth(size, c); @@ -451,7 +451,7 @@ uint32 FormatStringLinebreaks(char *str, int maxw) * 2. In all other cases force a linebreak at the last seen whitespace */ if (w > maxw) { if (last_space == NULL) { - str[-1] = '\0'; + *Utf8PrevChar(str) = '\0'; return num + (size << 16); } str = last_space; @@ -469,9 +469,17 @@ uint32 FormatStringLinebreaks(char *str, int maxw) } } end_of_inner_loop: - /* string didn't fit on line, so 'dummy' terminate and increase linecount */ + /* String didn't fit on line (or a '\n' was encountered), so 'dummy' terminate + * and increase linecount. We use Utf8PrevChar() as also non 1 char long + * whitespace seperators are supported */ num++; - str[-1] = '\0'; + char *s = Utf8PrevChar(str); + *s++ = '\0'; + + /* In which case (see above) we will shift remainder to left and close the gap */ + if (str - s >= 1) { + for (; str[-1] != '\0';) *s++ = *str++; + } } } |