mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-02-22 23:55:12 +00:00
AK: Add invert_case() and invert_case(StringView)
In the given String, invert_case() swaps lowercase characters with uppercase ones and vice versa.
This commit is contained in:
committed by
Linus Groh
parent
b1709c368f
commit
8ffa860bc3
@@ -462,6 +462,20 @@ String to_titlecase(StringView str)
|
||||
return builder.to_string();
|
||||
}
|
||||
|
||||
String invert_case(StringView str)
|
||||
{
|
||||
StringBuilder builder(str.length());
|
||||
|
||||
for (auto ch : str) {
|
||||
if (is_ascii_lower_alpha(ch))
|
||||
builder.append(to_ascii_uppercase(ch));
|
||||
else
|
||||
builder.append(to_ascii_lowercase(ch));
|
||||
}
|
||||
|
||||
return builder.to_string();
|
||||
}
|
||||
|
||||
String replace(StringView str, StringView needle, StringView replacement, bool all_occurrences)
|
||||
{
|
||||
if (str.is_empty())
|
||||
|
||||
Reference in New Issue
Block a user