diff options
author | Andreas Kling <kling@serenityos.org> | 2023-01-27 16:26:57 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-01-28 09:50:52 +0100 |
commit | 2dc657c77e8ce42250300ddcc4d77ac9ec831d1f (patch) | |
tree | 53a8e883a0edc6b1e2cf127218fc1009c448abdd /AK/Utf8View.h | |
parent | 0f4bbfdfb7e2f155fc05893f4846ec245056454c (diff) | |
download | serenity-2dc657c77e8ce42250300ddcc4d77ac9ec831d1f.zip |
AK: Add DeprecatedStringCodePointIterator
This is a safe iterator over the underlying code points. It will be used
in Jakt to assist in the migration away from DeprecatedString.
Diffstat (limited to 'AK/Utf8View.h')
-rw-r--r-- | AK/Utf8View.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/AK/Utf8View.h b/AK/Utf8View.h index 3da4de526b..f8c0553923 100644 --- a/AK/Utf8View.h +++ b/AK/Utf8View.h @@ -130,9 +130,32 @@ private: mutable bool m_have_length { false }; }; +class DeprecatedStringCodePointIterator { +public: + Optional<u32> next() + { + if (m_it.done()) + return {}; + auto value = *m_it; + ++m_it; + return value; + } + + DeprecatedStringCodePointIterator(DeprecatedString string) + : m_string(move(string)) + , m_it(Utf8View(m_string).begin()) + { + } + +private: + DeprecatedString m_string; + Utf8CodePointIterator m_it; +}; + } #if USING_AK_GLOBALLY +using AK::DeprecatedStringCodePointIterator; using AK::Utf8CodePointIterator; using AK::Utf8View; #endif |