summaryrefslogtreecommitdiff
path: root/AK/StringView.cpp
diff options
context:
space:
mode:
authorBrian Gianforcaro <bgianf@serenityos.org>2022-01-09 01:51:02 -0800
committerAndreas Kling <kling@serenityos.org>2022-01-12 13:03:44 +0100
commitcd42f64bc79683533f08bb3ea6c8b7afa804bcf6 (patch)
treef30d74c00b3e844c0b81324e252aa0a67880eb67 /AK/StringView.cpp
parentfaf1fa0a8466123f2ae395b4b72541a19fb0d8b4 (diff)
downloadserenity-cd42f64bc79683533f08bb3ea6c8b7afa804bcf6.zip
AK: Rewrite StringView::split_view(char..), using StringView
Diffstat (limited to 'AK/StringView.cpp')
-rw-r--r--AK/StringView.cpp20
1 files changed, 2 insertions, 18 deletions
diff --git a/AK/StringView.cpp b/AK/StringView.cpp
index 79273bc5c7..a83e65e229 100644
--- a/AK/StringView.cpp
+++ b/AK/StringView.cpp
@@ -36,24 +36,8 @@ StringView::StringView(const ByteBuffer& buffer)
Vector<StringView> StringView::split_view(const char separator, bool keep_empty) const
{
- if (is_empty())
- return {};
-
- Vector<StringView> v;
- size_t substart = 0;
- for (size_t i = 0; i < length(); ++i) {
- char ch = characters_without_null_termination()[i];
- if (ch == separator) {
- size_t sublen = i - substart;
- if (sublen != 0 || keep_empty)
- v.append(substring_view(substart, sublen));
- substart = i + 1;
- }
- }
- size_t taillen = length() - substart;
- if (taillen != 0 || keep_empty)
- v.append(substring_view(substart, taillen));
- return v;
+ StringView seperator_view { &separator, 1 };
+ return split_view(seperator_view, keep_empty);
}
Vector<StringView> StringView::split_view(StringView separator, bool keep_empty) const