1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-09 09:34:57 +09:00

AK: Implement Utf8CodepointIterator::peek(size_t)

This adds a peek method for Utf8CodepointIterator, which enables it to
be used in some parsing cases where peeking is necessary.

peek(0) is equivalent to operator*, expect that peek() does not contain
any assertions and will just return an empty Optional<u32>.

This also implements a test case for iterating UTF-8.
This commit is contained in:
Max Wipfli 2021-05-24 00:29:16 +02:00 committed by Andreas Kling
parent 31f6ba0952
commit 14506e8f5e
Notes: sideshowbarker 2024-07-18 17:04:53 +09:00
3 changed files with 55 additions and 0 deletions

View file

@ -25,6 +25,8 @@ public:
bool operator!=(const Utf8CodepointIterator&) const;
Utf8CodepointIterator& operator++();
u32 operator*() const;
// NOTE: This returns {} if the peek is at or past EOF.
Optional<u32> peek(size_t offset = 0) const;
ssize_t operator-(const Utf8CodepointIterator& other) const
{