1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 03:07:43 +00:00

AK: Add String::trim_spaces()

This commit is contained in:
Linus Groh 2020-05-11 01:43:33 +01:00 committed by Andreas Kling
parent 673527d314
commit d20e26c690
2 changed files with 16 additions and 0 deletions

View file

@ -369,6 +369,20 @@ int String::replace(const String& needle, const String& replacement, bool all_oc
return positions.size();
}
String String::trim_spaces() const
{
size_t start = 0;
size_t end = length();
while (characters()[start] == ' ')
++start;
while (characters()[end] == ' ') {
if (end <= start)
return "";
--end;
}
return substring(start, end - start);
}
String escape_html_entities(const StringView& html)
{
StringBuilder builder;