mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 04:09:13 +00:00
AK+LibWeb: Add {Fly,}String::to_ascii_{upper,lower}_case()
These don't have to worry about the input not being valid UTF-8 and so can be infallible (and can even return self if no changes needed.) We use this instead of Infra::to_ascii_{upper,lower}_case in LibWeb.
This commit is contained in:
parent
dd419b5a8d
commit
073bcfd386
Notes:
github-actions[bot]
2024-10-14 18:49:00 +00:00
Author: https://github.com/awesomekling
Commit: 073bcfd386
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1796
16 changed files with 147 additions and 13 deletions
|
@ -1416,3 +1416,27 @@ TEST_CASE(ends_with)
|
|||
EXPECT(emoji.ends_with(0x1F643));
|
||||
EXPECT(!emoji.ends_with(0x1F600));
|
||||
}
|
||||
|
||||
TEST_CASE(to_ascii_lowercase)
|
||||
{
|
||||
EXPECT_EQ("foobar"_string.to_ascii_lowercase(), "foobar"_string);
|
||||
EXPECT_EQ("FooBar"_string.to_ascii_lowercase(), "foobar"_string);
|
||||
EXPECT_EQ("FOOBAR"_string.to_ascii_lowercase(), "foobar"_string);
|
||||
|
||||
// NOTE: We expect to_ascii_lowercase() to return the same underlying string if no changes are needed.
|
||||
auto long_string = "this is a long string that cannot use the short string optimization"_string;
|
||||
auto lowercased = long_string.to_ascii_lowercase();
|
||||
EXPECT_EQ(long_string.bytes().data(), lowercased.bytes().data());
|
||||
}
|
||||
|
||||
TEST_CASE(to_ascii_uppercase)
|
||||
{
|
||||
EXPECT_EQ("foobar"_string.to_ascii_uppercase(), "FOOBAR"_string);
|
||||
EXPECT_EQ("FooBar"_string.to_ascii_uppercase(), "FOOBAR"_string);
|
||||
EXPECT_EQ("FOOBAR"_string.to_ascii_uppercase(), "FOOBAR"_string);
|
||||
|
||||
// NOTE: We expect to_ascii_uppercase() to return the same underlying string if no changes are needed.
|
||||
auto long_string = "THIS IS A LONG STRING THAT CANNOT USE THE SHORT STRING OPTIMIZATION"_string;
|
||||
auto uppercased = long_string.to_ascii_uppercase();
|
||||
EXPECT_EQ(long_string.bytes().data(), uppercased.bytes().data());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue