0
0
mirror of https://github.com/vim/vim.git synced 2025-09-27 04:14:06 -04:00

patch 8.2.2893: multi-byte text in popup title shows up wrong

Problem:    Multi-byte text in popup title shows up wrong.
Solution:   Use the character width instead of the byte length. (Ralf Schandl,
            closes #8267, closes #8264)
This commit is contained in:
Ralf Schandl
2021-05-28 14:12:14 +02:00
committed by Bram Moolenaar
parent 89dcb4dce3
commit bc869874fe
5 changed files with 69 additions and 8 deletions

View File

@@ -120,6 +120,37 @@ test_trunc_string(void)
vim_free(s);
}
/*
* Test trunc_string() with mbyte chars.
*/
static void
test_trunc_string_mbyte(void)
{
char_u *buf; // allocated every time to find uninit errors
char_u *s;
buf = alloc(40);
s = vim_strsave((char_u *)"Ä text tha just fits");
trunc_string(s, buf, 20, 40);
assert(STRCMP(buf, "Ä text tha just fits") == 0);
vim_free(buf);
vim_free(s);
buf = alloc(40);
s = vim_strsave((char_u *)"a text ÄÖÜä nott fits");
trunc_string(s, buf, 20, 40);
assert(STRCMP(buf, "a text Ä...nott fits") == 0);
vim_free(buf);
vim_free(s);
buf = alloc(40);
s = vim_strsave((char_u *)"a text that not fitsÄ");
trunc_string(s, buf, 20, 40);
assert(STRCMP(buf, "a text t...not fitsÄ") == 0);
vim_free(buf);
vim_free(s);
}
/*
* Test vim_snprintf() with a focus on checking that truncation is
* correct when buffer is small, since it cannot be tested from
@@ -286,6 +317,7 @@ main(int argc, char **argv)
set_option_value((char_u *)"encoding", 0, (char_u *)"utf-8", 0);
init_chartab();
test_trunc_string();
test_trunc_string_mbyte();
test_vim_snprintf();
set_option_value((char_u *)"encoding", 0, (char_u *)"latin1", 0);