AK: Add String::trim_spaces()
This commit is contained in:
parent
673527d314
commit
d20e26c690
Notes:
sideshowbarker
2024-07-19 06:43:46 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/d20e26c6902 Pull-request: https://github.com/SerenityOS/serenity/pull/2189 Reviewed-by: https://github.com/awesomekling
2 changed files with 16 additions and 0 deletions
|
@ -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;
|
||||
|
|
|
@ -114,6 +114,8 @@ public:
|
|||
String to_lowercase() const;
|
||||
String to_uppercase() const;
|
||||
|
||||
String trim_spaces() const;
|
||||
|
||||
bool equals_ignoring_case(const StringView&) const;
|
||||
|
||||
bool contains(const String&) const;
|
||||
|
|
Loading…
Add table
Reference in a new issue