1
0
mirror of https://github.com/irssi/irssi.git synced 2024-12-04 14:46:39 -05:00

make format_real_length left-collecting

This commit is contained in:
ailin-nemui 2017-05-05 14:45:13 +02:00
parent e405330e04
commit 451019d05d

View File

@ -480,27 +480,30 @@ int format_real_length(const char *str, int len)
start = str; start = str;
tmp = g_string_new(NULL); tmp = g_string_new(NULL);
while (*str != '\0' && len > 0) { while (*str != '\0') {
oldstr = str;
if (*str == '%' && str[1] != '\0') { if (*str == '%' && str[1] != '\0') {
str++; str++;
if (*str != '%') { if (*str != '%') {
adv = format_expand_styles(tmp, &str, NULL); adv = format_expand_styles(tmp, &str, NULL);
str += adv; if (adv) {
if (adv) str += adv;
continue; continue;
} }
/* discount for unknown % */
/* %% or unknown %code, written as-is */ if (--len < 0) {
if (*str != '%') { str = oldstr;
if (--len == 0) break;
break; }
oldstr = str;
} }
} }
oldstr = str;
len -= string_advance(&str, utf8); len -= string_advance(&str, utf8);
if (len < 0) if (len < 0) {
str = oldstr; str = oldstr;
break;
}
} }
g_string_free(tmp, TRUE); g_string_free(tmp, TRUE);