summaryrefslogtreecommitdiff
path: root/AK/Utf32View.cpp
blob: ebb4bbd1f7a96ac051602b802fd1873d90e15e70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
 * Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include <AK/StringBuilder.h>
#include <AK/Utf32View.h>

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);
}

}