blob: e4396874301e21e0bb5c9461b3ecd1e1f961ddb5 (
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
36
37
38
|
#include "utf8_iterator.hpp"
namespace fud {
std::optional<ExtUtf8> Utf8Iterator::peek() const
{
if (m_index >= m_view.length()) {
return std::nullopt;
}
auto utf8 = ExtUtf8::fromStringView(m_view, m_index);
if (!utf8.valid()) {
return std::nullopt;
}
return utf8;
}
std::optional<ExtUtf8> Utf8Iterator::next()
{
if (m_index >= m_view.length()) {
m_index = m_view.length();
return std::nullopt;
}
auto utf8 = ExtUtf8::fromStringView(m_view, m_index);
if (!utf8.valid()) {
m_index = m_view.length();
return std::nullopt;
}
m_index += utf8.size();
return utf8;
}
} // namespace fud
|