summaryrefslogtreecommitdiff
path: root/AK/StringView.h
diff options
context:
space:
mode:
authorMax Wipfli <mail@maxwipfli.ch>2021-07-01 14:58:37 +0200
committerAndreas Kling <kling@serenityos.org>2021-07-02 21:54:21 +0200
commit56253bf3895e258729130a7ec22acff74e5b4212 (patch)
treedcc590c88205f8872c610f0d455002bee379176e /AK/StringView.h
parent3ea65200d82a59530ed94136c8fb8baa9461d69c (diff)
downloadserenity-56253bf3895e258729130a7ec22acff74e5b4212.zip
AK: Reimplement StringView::find methods in StringUtils
This patch reimplements the StringView::find methods in StringUtils, so they can also be used by String. The methods now also take an optional start parameter, which moves their API in line with String's respective methods. This also implements a StringView::find_ast(char) method, which is currently functionally equivalent to find_last_of(char). This is because find_last_of(char) will be removed in a further commit.
Diffstat (limited to 'AK/StringView.h')
-rw-r--r--AK/StringView.h6
1 files changed, 4 insertions, 2 deletions
diff --git a/AK/StringView.h b/AK/StringView.h
index 356f65f8f2..1c4da71248 100644
--- a/AK/StringView.h
+++ b/AK/StringView.h
@@ -92,8 +92,10 @@ public:
Optional<size_t> find_last_of(char) const;
Optional<size_t> find_last_of(const StringView&) const;
- Optional<size_t> find(const StringView&) const;
- Optional<size_t> find(char c) const;
+ [[nodiscard]] Optional<size_t> find(char needle, size_t start = 0) const { return StringUtils::find(*this, needle, start); }
+ [[nodiscard]] Optional<size_t> find(StringView const& needle, size_t start = 0) const { return StringUtils::find(*this, needle, start); }
+ [[nodiscard]] Optional<size_t> find_last(char needle) const { return StringUtils::find_last(*this, needle); }
+ // FIXME: Implement find_last(StringView const&) for API symmetry.
[[nodiscard]] constexpr StringView substring_view(size_t start, size_t length) const
{