mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:47:44 +00:00
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.
This commit is contained in:
parent
0f4bbfdfb7
commit
2dc657c77e
4 changed files with 33 additions and 0 deletions
|
@ -11,6 +11,7 @@
|
||||||
#include <AK/Function.h>
|
#include <AK/Function.h>
|
||||||
#include <AK/StdLibExtras.h>
|
#include <AK/StdLibExtras.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
|
#include <AK/Utf8View.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
@ -449,4 +450,9 @@ Vector<size_t> DeprecatedString::find_all(StringView needle) const
|
||||||
return StringUtils::find_all(*this, needle);
|
return StringUtils::find_all(*this, needle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DeprecatedStringCodePointIterator DeprecatedString::code_points() const
|
||||||
|
{
|
||||||
|
return DeprecatedStringCodePointIterator(*this);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,6 +129,8 @@ public:
|
||||||
|
|
||||||
[[nodiscard]] bool is_whitespace() const { return StringUtils::is_whitespace(*this); }
|
[[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
|
[[nodiscard]] DeprecatedString trim(StringView characters, TrimMode mode = TrimMode::Both) const
|
||||||
{
|
{
|
||||||
auto trimmed_view = StringUtils::trim(view(), characters, mode);
|
auto trimmed_view = StringUtils::trim(view(), characters, mode);
|
||||||
|
|
|
@ -30,6 +30,7 @@ class JsonValue;
|
||||||
class StackInfo;
|
class StackInfo;
|
||||||
class DeprecatedFlyString;
|
class DeprecatedFlyString;
|
||||||
class DeprecatedString;
|
class DeprecatedString;
|
||||||
|
class DeprecatedStringCodePointIterator;
|
||||||
class StringBuilder;
|
class StringBuilder;
|
||||||
class StringImpl;
|
class StringImpl;
|
||||||
class StringView;
|
class StringView;
|
||||||
|
@ -156,6 +157,7 @@ using AK::CircularBuffer;
|
||||||
using AK::CircularQueue;
|
using AK::CircularQueue;
|
||||||
using AK::DeprecatedFlyString;
|
using AK::DeprecatedFlyString;
|
||||||
using AK::DeprecatedString;
|
using AK::DeprecatedString;
|
||||||
|
using AK::DeprecatedStringCodePointIterator;
|
||||||
using AK::DoublyLinkedList;
|
using AK::DoublyLinkedList;
|
||||||
using AK::Error;
|
using AK::Error;
|
||||||
using AK::ErrorOr;
|
using AK::ErrorOr;
|
||||||
|
|
|
@ -130,9 +130,32 @@ private:
|
||||||
mutable bool m_have_length { false };
|
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
|
#if USING_AK_GLOBALLY
|
||||||
|
using AK::DeprecatedStringCodePointIterator;
|
||||||
using AK::Utf8CodePointIterator;
|
using AK::Utf8CodePointIterator;
|
||||||
using AK::Utf8View;
|
using AK::Utf8View;
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue