summaryrefslogtreecommitdiff
path: root/include/utf8_iterator.hpp
blob: 1f9674bf6ab4730e9c36867d262cd503c2ab7288 (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
39
#ifndef FUD_UTF8_ITERATOR_HPP
#define FUD_UTF8_ITERATOR_HPP

#include "string.hpp"
#include "utf8.hpp"

#include <cstddef>
#include <optional>

namespace fud {

class Utf8Iterator {
  private:
    size_t m_index{0};
    // NOLINTBEGIN(cppcoreguidelines-avoid-const-or-ref-data-members)
    const StringView m_view;
    // NOLINTEND(cppcoreguidelines-avoid-const-or-ref-data-members)

  public:
    explicit constexpr Utf8Iterator(const String& extString) : m_view{extString}
    {
    }

    explicit constexpr Utf8Iterator(const StringView& view) : m_view{view}
    {
    }

    constexpr void reset()
    {
        m_index = 0;
    }

    [[nodiscard]] std::optional<ExtUtf8> peek() const;
    std::optional<ExtUtf8> next();
};

} // namespace fud

#endif