AK: Prepare Utf32View for use within templated LibGfx contexts

Forward declare its iterator and add a peek() method analagous to
Utf8CodePointIterator::peek().
This commit is contained in:
Timothy Flynn 2023-02-20 14:04:42 -05:00 committed by Andreas Kling
parent 0f20586346
commit 832e9b8302
Notes: sideshowbarker 2024-07-17 00:37:23 +09:00
3 changed files with 23 additions and 0 deletions

View file

@ -44,6 +44,7 @@ class Time;
class URL;
class String;
class Utf16View;
class Utf32CodePointIterator;
class Utf32View;
class Utf8CodePointIterator;
class Utf8View;
@ -201,6 +202,7 @@ using AK::Time;
using AK::Traits;
using AK::URL;
using AK::Utf16View;
using AK::Utf32CodePointIterator;
using AK::Utf32View;
using AK::Utf8CodePointIterator;
using AK::Utf8View;

View file

@ -9,6 +9,24 @@
namespace AK {
Optional<u32> Utf32CodePointIterator::peek(size_t offset) const
{
if (offset == 0) {
if (this->done())
return {};
return this->operator*();
}
auto new_iterator = *this;
for (size_t index = 0; index < offset; ++index) {
++new_iterator;
if (new_iterator.done())
return {};
}
return *new_iterator;
}
ErrorOr<void> Formatter<Utf32View>::format(FormatBuilder& builder, Utf32View const& string)
{
return builder.builder().try_append(string);

View file

@ -43,6 +43,9 @@ public:
return *m_ptr;
}
// NOTE: This returns {} if the peek is at or past EOF.
Optional<u32> peek(size_t offset = 0) const;
constexpr int code_point_length_in_bytes() const { return sizeof(u32); }
bool done() const { return !m_length; }