mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
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:
parent
0f20586346
commit
832e9b8302
Notes:
sideshowbarker
2024-07-17 00:37:23 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/832e9b8302 Pull-request: https://github.com/SerenityOS/serenity/pull/17558
3 changed files with 23 additions and 0 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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; }
|
||||
|
||||
|
|
Loading…
Reference in a new issue