From d842d04be4b4523800f0182f9994151aeb51463d Mon Sep 17 00:00:00 2001 From: Jonne Ransijn Date: Thu, 14 Nov 2024 20:28:30 +0100 Subject: [PATCH] AK: Remove `DeprecatedStringCodePointIterator` The functionality in this class is no longer used, we can just use `Utf8View` instead. --- AK/ByteString.cpp | 4 ++-- AK/ByteString.h | 3 ++- AK/Forward.h | 2 -- AK/Utf8View.h | 36 +----------------------------------- 4 files changed, 5 insertions(+), 40 deletions(-) diff --git a/AK/ByteString.cpp b/AK/ByteString.cpp index b92f1932556..ff12f3e62b3 100644 --- a/AK/ByteString.cpp +++ b/AK/ByteString.cpp @@ -387,9 +387,9 @@ Vector ByteString::find_all(StringView needle) const return StringUtils::find_all(*this, needle); } -DeprecatedStringCodePointIterator ByteString::code_points() const +Utf8CodePointIterator ByteString::code_points() const& { - return DeprecatedStringCodePointIterator(*this); + return Utf8CodePointIterator { reinterpret_cast(characters()), length() }; } ErrorOr ByteString::from_utf8(ReadonlyBytes bytes) diff --git a/AK/ByteString.h b/AK/ByteString.h index f68ea6b5184..9b399671759 100644 --- a/AK/ByteString.h +++ b/AK/ByteString.h @@ -141,7 +141,8 @@ public: [[nodiscard]] bool is_whitespace() const { return StringUtils::is_whitespace(*this); } - [[nodiscard]] DeprecatedStringCodePointIterator code_points() const; + [[nodiscard]] Utf8CodePointIterator code_points() const&; + [[nodiscard]] Utf8CodePointIterator code_points() const&& = delete; [[nodiscard]] ByteString trim(StringView characters, TrimMode mode = TrimMode::Both) const { diff --git a/AK/Forward.h b/AK/Forward.h index 68b5af27b55..e1abf382013 100644 --- a/AK/Forward.h +++ b/AK/Forward.h @@ -31,7 +31,6 @@ class ConstrainedStream; class CountingStream; class DeprecatedFlyString; class ByteString; -class DeprecatedStringCodePointIterator; class Duration; class Error; class FlyString; @@ -163,7 +162,6 @@ using AK::CircularQueue; using AK::ConstrainedStream; using AK::CountingStream; using AK::DeprecatedFlyString; -using AK::DeprecatedStringCodePointIterator; using AK::DoublyLinkedList; using AK::Error; using AK::ErrorOr; diff --git a/AK/Utf8View.h b/AK/Utf8View.h index 700afcdbfff..79a26594d8f 100644 --- a/AK/Utf8View.h +++ b/AK/Utf8View.h @@ -19,6 +19,7 @@ class Utf8View; class Utf8CodePointIterator { friend class Utf8View; + friend class ByteString; public: Utf8CodePointIterator() = default; @@ -184,40 +185,6 @@ private: mutable bool m_have_length { false }; }; -class DeprecatedStringCodePointIterator { -public: - Optional next() - { - if (m_it.done()) - return {}; - auto value = *m_it; - ++m_it; - return value; - } - - [[nodiscard]] Optional peek() const - { - if (m_it.done()) - return {}; - return *m_it; - } - - [[nodiscard]] size_t byte_offset() const - { - return Utf8View(m_string).byte_offset_of(m_it); - } - - DeprecatedStringCodePointIterator(ByteString string) - : m_string(move(string)) - , m_it(Utf8View(m_string).begin()) - { - } - -private: - ByteString m_string; - Utf8CodePointIterator m_it; -}; - template<> struct Formatter : Formatter { ErrorOr format(FormatBuilder&, Utf8View const&); @@ -312,7 +279,6 @@ inline u32 Utf8CodePointIterator::operator*() const } #if USING_AK_GLOBALLY -using AK::DeprecatedStringCodePointIterator; using AK::Utf8CodePointIterator; using AK::Utf8View; #endif