1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 06:17:34 +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:
Andreas Kling 2023-01-27 16:26:57 +01:00
parent 0f4bbfdfb7
commit 2dc657c77e
4 changed files with 33 additions and 0 deletions

View file

@ -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