AK: Do not append string bytes as code points when title-casing a string
By appending individual bytes as code points, we were "breaking apart" multi-byte UTF-8 code points. This now behaves the same way as the invert_case() helper in StringUtils.
This commit is contained in:
parent
66e424a084
commit
b9dc0b7d1b
Notes:
sideshowbarker
2024-07-19 01:59:31 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/b9dc0b7d1b Pull-request: https://github.com/SerenityOS/serenity/pull/15716
2 changed files with 4 additions and 2 deletions
|
@ -465,9 +465,9 @@ String to_titlecase(StringView str)
|
|||
|
||||
for (auto ch : str) {
|
||||
if (next_is_upper)
|
||||
builder.append_code_point(to_ascii_uppercase(ch));
|
||||
builder.append(to_ascii_uppercase(ch));
|
||||
else
|
||||
builder.append_code_point(to_ascii_lowercase(ch));
|
||||
builder.append(to_ascii_lowercase(ch));
|
||||
next_is_upper = ch == ' ';
|
||||
}
|
||||
|
||||
|
|
|
@ -387,4 +387,6 @@ TEST_CASE(to_titlecase)
|
|||
EXPECT_EQ(AK::StringUtils::to_titlecase("foo bar"sv), "Foo Bar"sv);
|
||||
EXPECT_EQ(AK::StringUtils::to_titlecase("foo bar"sv), "Foo Bar"sv);
|
||||
EXPECT_EQ(AK::StringUtils::to_titlecase(" foo bar "sv), " Foo Bar "sv);
|
||||
EXPECT_EQ(AK::StringUtils::to_titlecase("\xc3\xa7"sv), "\xc3\xa7"sv); // U+00E7 LATIN SMALL LETTER C WITH CEDILLA
|
||||
EXPECT_EQ(AK::StringUtils::to_titlecase("\xe1\x80\x80"sv), "\xe1\x80\x80"sv); // U+1000 MYANMAR LETTER KA
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue