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:
Timothy Flynn 2022-10-20 08:44:18 -04:00 committed by Linus Groh
parent 66e424a084
commit b9dc0b7d1b
2 changed files with 4 additions and 2 deletions

View file

@ -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 == ' ';
}

View file

@ -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
}