lib: vsprintf: correct printing of Unicode strings
The width and precision of the printf() function refer to the number of characters not to the number of bytes printed. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
This commit is contained in:
parent
f11a164b58
commit
31bd711cd0
@ -280,18 +280,13 @@ static char *string16(char *buf, char *end, u16 *s, int field_width,
|
|||||||
int precision, int flags)
|
int precision, int flags)
|
||||||
{
|
{
|
||||||
u16 *str = s ? s : L"<NULL>";
|
u16 *str = s ? s : L"<NULL>";
|
||||||
int utf16_len = u16_strnlen(str, precision);
|
ssize_t len = utf16_strnlen(str, precision);
|
||||||
u8 utf8[utf16_len * MAX_UTF8_PER_UTF16];
|
|
||||||
int utf8_len, i;
|
|
||||||
|
|
||||||
utf8_len = utf16_to_utf8(utf8, str, utf16_len) - utf8;
|
|
||||||
|
|
||||||
if (!(flags & LEFT))
|
if (!(flags & LEFT))
|
||||||
while (utf8_len < field_width--)
|
for (; len < field_width; --field_width)
|
||||||
ADDCH(buf, ' ');
|
ADDCH(buf, ' ');
|
||||||
for (i = 0; i < utf8_len; ++i)
|
utf16_utf8_strncpy(&buf, str, len);
|
||||||
ADDCH(buf, utf8[i]);
|
for (; len < field_width; --field_width)
|
||||||
while (utf8_len < field_width--)
|
|
||||||
ADDCH(buf, ' ');
|
ADDCH(buf, ' ');
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user