diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2022-12-03 11:40:30 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2022-12-10 16:05:14 +0100 |
commit | e5cbbd781d814e321845598775f594f0f808e18e (patch) | |
tree | 32dde8ec949ddaa0c9d239338e0a0b729d73c7d6 /tests/unit/core | |
parent | 0e6677fbcbb81e972e5f210e5dd7a2186fb7ba66 (diff) | |
download | weechat-e5cbbd781d814e321845598775f594f0f808e18e.zip |
core: optimize and fix function utf8_strlen_screen with non printable chars
When there non printable chars, the return of the function was 1.
For example utf8_strlen_screen("abc\x01") now returns 4 instead of 1.
In addition the function has been optimized to not use the `mbstowcs` function
which is slow; result is up to 15% faster.
Diffstat (limited to 'tests/unit/core')
-rw-r--r-- | tests/unit/core/test-core-utf8.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/tests/unit/core/test-core-utf8.cpp b/tests/unit/core/test-core-utf8.cpp index 14e397402..0bd8e015b 100644 --- a/tests/unit/core/test-core-utf8.cpp +++ b/tests/unit/core/test-core-utf8.cpp @@ -495,9 +495,9 @@ TEST(CoreUtf8, Size) /* ël as iso-8859-15: invalid UTF-8 */ LONGS_EQUAL(1, utf8_char_size_screen ("\xebl")); /* ëlm as iso-8859-15: invalid UTF-8 */ - LONGS_EQUAL(1, utf8_char_size_screen ("\xeblm")); + LONGS_EQUAL(2, utf8_char_size_screen ("\xeblm")); /* ëlmn as iso-8859-15: invalid UTF-8 */ - LONGS_EQUAL(1, utf8_char_size_screen ("\xeblmn")); + LONGS_EQUAL(2, utf8_char_size_screen ("\xeblmn")); /* length of string (in chars) */ LONGS_EQUAL(0, utf8_strlen (NULL)); @@ -530,16 +530,18 @@ TEST(CoreUtf8, Size) LONGS_EQUAL(1, utf8_strlen_screen ("\x7f")); LONGS_EQUAL(1, utf8_strlen_screen ("\x01")); LONGS_EQUAL(4, utf8_strlen_screen (UTF8_NOEL_VALID)); + LONGS_EQUAL(4, utf8_strlen_screen ("abc\x01")); + LONGS_EQUAL(8, utf8_strlen_screen ("a" "\x01" UTF8_NOEL_VALID "\x02" "b")); LONGS_EQUAL(1, utf8_strlen_screen (UNICODE_SOFT_HYPHEN)); - LONGS_EQUAL(3, utf8_strlen_screen ("a" UNICODE_SOFT_HYPHEN "b")); + LONGS_EQUAL(5, utf8_strlen_screen ("a" "\x01" UNICODE_SOFT_HYPHEN "\x02" "b")); LONGS_EQUAL(0, utf8_strlen_screen (UNICODE_ZERO_WIDTH_SPACE)); - LONGS_EQUAL(2, utf8_strlen_screen ("a" UNICODE_ZERO_WIDTH_SPACE "b")); + LONGS_EQUAL(4, utf8_strlen_screen ("a" "\x01" UNICODE_ZERO_WIDTH_SPACE "\x02" "b")); LONGS_EQUAL(2, utf8_strlen_screen (UNICODE_SNOWMAN)); - LONGS_EQUAL(4, utf8_strlen_screen ("a" UNICODE_SNOWMAN "b")); + LONGS_EQUAL(6, utf8_strlen_screen ("a" "\x01" UNICODE_SNOWMAN "\x02" "b")); LONGS_EQUAL(2, utf8_strlen_screen (UNICODE_CJK_YELLOW)); - LONGS_EQUAL(4, utf8_strlen_screen ("a" UNICODE_CJK_YELLOW "b")); + LONGS_EQUAL(6, utf8_strlen_screen ("a" "\x01" UNICODE_CJK_YELLOW "\x02" "b")); LONGS_EQUAL(2, utf8_strlen_screen (UNICODE_HAN_CHAR)); - LONGS_EQUAL(4, utf8_strlen_screen ("a" UNICODE_HAN_CHAR "b")); + LONGS_EQUAL(6, utf8_strlen_screen ("a" "\x01" UNICODE_HAN_CHAR "\x02" "b")); /* length of Tabulation */ LONGS_EQUAL(1, utf8_strlen_screen ("\t")); |