summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AK/DeprecatedString.cpp6
-rw-r--r--AK/DeprecatedString.h2
-rw-r--r--AK/Forward.h2
-rw-r--r--AK/Utf8View.h23
4 files changed, 33 insertions, 0 deletions
diff --git a/AK/DeprecatedString.cpp b/AK/DeprecatedString.cpp
index 957dc3d675..0b1064f990 100644
--- a/AK/DeprecatedString.cpp
+++ b/AK/DeprecatedString.cpp
@@ -11,6 +11,7 @@
#include <AK/Function.h>
#include <AK/StdLibExtras.h>
#include <AK/StringView.h>
+#include <AK/Utf8View.h>
#include <AK/Vector.h>
namespace AK {
@@ -449,4 +450,9 @@ Vector<size_t> DeprecatedString::find_all(StringView needle) const
return StringUtils::find_all(*this, needle);
}
+DeprecatedStringCodePointIterator DeprecatedString::code_points() const
+{
+ return DeprecatedStringCodePointIterator(*this);
+}
+
}
diff --git a/AK/DeprecatedString.h b/AK/DeprecatedString.h
index 1fde665380..0155fcdf19 100644
--- a/AK/DeprecatedString.h
+++ b/AK/DeprecatedString.h
@@ -129,6 +129,8 @@ public:
[[nodiscard]] bool is_whitespace() const { return StringUtils::is_whitespace(*this); }
+ [[nodiscard]] DeprecatedStringCodePointIterator code_points() const;
+
[[nodiscard]] DeprecatedString trim(StringView characters, TrimMode mode = TrimMode::Both) const
{
auto trimmed_view = StringUtils::trim(view(), characters, mode);
diff --git a/AK/Forward.h b/AK/Forward.h
index baa16afa51..786ab02f6c 100644
--- a/AK/Forward.h
+++ b/AK/Forward.h
@@ -30,6 +30,7 @@ class JsonValue;
class StackInfo;
class DeprecatedFlyString;
class DeprecatedString;
+class DeprecatedStringCodePointIterator;
class StringBuilder;
class StringImpl;
class StringView;
@@ -156,6 +157,7 @@ using AK::CircularBuffer;
using AK::CircularQueue;
using AK::DeprecatedFlyString;
using AK::DeprecatedString;
+using AK::DeprecatedStringCodePointIterator;
using AK::DoublyLinkedList;
using AK::Error;
using AK::ErrorOr;
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