mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 08:34:57 +00:00
AK: Implement method to convert a String/StringView to title case
This implementation preserves consecutive spaces in the orginal string.
This commit is contained in:
parent
d2af27d2d0
commit
262e412634
7 changed files with 43 additions and 0 deletions
|
@ -411,6 +411,22 @@ String to_snakecase(const StringView& str)
|
|||
return builder.to_string();
|
||||
}
|
||||
|
||||
String to_titlecase(StringView const& str)
|
||||
{
|
||||
StringBuilder builder;
|
||||
bool next_is_upper = true;
|
||||
|
||||
for (auto ch : str) {
|
||||
if (next_is_upper)
|
||||
builder.append_code_point(to_ascii_uppercase(ch));
|
||||
else
|
||||
builder.append_code_point(to_ascii_lowercase(ch));
|
||||
next_is_upper = ch == ' ';
|
||||
}
|
||||
|
||||
return builder.to_string();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue