mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 08:54:58 +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:
parent
b1709c368f
commit
8ffa860bc3
4 changed files with 21 additions and 0 deletions
|
@ -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())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue