From 268d81a56c203e46711720b65a21d4b09a03acec Mon Sep 17 00:00:00 2001 From: Max Wipfli Date: Thu, 1 Jul 2021 17:34:25 +0200 Subject: [PATCH] AK: Add String::find_last() and inline String::find() methods This adds the String::find_last() as wrapper for StringUtils::find_last, which is another step in harmonizing the String and StringView APIs where possible. This also inlines the find() methods, as they are simple wrappers around StringUtils functions without any additional logic. --- AK/String.cpp | 10 ---------- AK/String.h | 6 ++++-- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/AK/String.cpp b/AK/String.cpp index d82f6ab8b4..66e29ef77d 100644 --- a/AK/String.cpp +++ b/AK/String.cpp @@ -459,14 +459,4 @@ String String::vformatted(StringView fmtstr, TypeErasedFormatParams params) return builder.to_string(); } -Optional String::find(char c, size_t start) const -{ - return find(StringView { &c, 1 }, start); -} - -Optional String::find(StringView const& view, size_t start) const -{ - return StringUtils::find(*this, view, start); -} - } diff --git a/AK/String.h b/AK/String.h index 6037e478ec..94100f376e 100644 --- a/AK/String.h +++ b/AK/String.h @@ -141,8 +141,10 @@ public: [[nodiscard]] Vector split_limit(char separator, size_t limit, bool keep_empty = false) const; [[nodiscard]] Vector split(char separator, bool keep_empty = false) const; - [[nodiscard]] Optional find(char, size_t start = 0) const; - [[nodiscard]] Optional find(StringView const&, size_t start = 0) const; + [[nodiscard]] Optional find(char needle, size_t start = 0) const { return StringUtils::find(*this, needle, start); } + [[nodiscard]] Optional find(StringView const& needle, size_t start = 0) const { return StringUtils::find(*this, needle, start); } + [[nodiscard]] Optional find_last(char needle) const { return StringUtils::find_last(*this, needle); } + // FIXME: Implement find_last(StringView const&) for API symmetry. [[nodiscard]] Vector find_all(StringView const& needle) const { return StringUtils::find_all(*this, needle); } [[nodiscard]] String substring(size_t start) const;