1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 05:47:34 +00:00

AK: Add trim() method to String, StringView and StringUtils

The methods added make it possible to use the trim mechanism with
specified characters, unlike trim_whitespace(), which uses predefined
characters.
This commit is contained in:
Max Wipfli 2021-05-25 09:42:01 +02:00 committed by Andreas Kling
parent 14506e8f5e
commit 0e4f7aa8e8
4 changed files with 17 additions and 5 deletions

View file

@ -119,9 +119,14 @@ public:
[[nodiscard]] bool is_whitespace() const { return StringUtils::is_whitespace(*this); }
#ifndef KERNEL
[[nodiscard]] String trim(const StringView& characters, TrimMode mode = TrimMode::Both) const
{
return StringUtils::trim(view(), characters, mode);
}
[[nodiscard]] String trim_whitespace(TrimMode mode = TrimMode::Both) const
{
return StringUtils::trim_whitespace(StringView { characters(), length() }, mode);
return StringUtils::trim_whitespace(view(), mode);
}
#endif