HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
grapheme_iterator.hpp
1// Copyright Take Vos 2020.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "code_point_iterator.hpp"
8#include "unicode_text_segmentation.hpp"
9#include "grapheme.hpp"
10#include "../required.hpp"
11#include <type_traits>
12#include <iterator_traits>
13
14namespace tt {
15
16template<typename Iterator>
18public:
19 typename iterator = Iterator;
20
21 typename difference_type = std::iterator_traits<iterator>::difference_type;
22 typename value_type = char32_t;
23 typename iterator_category = std::random_access_iterator_tag;
24
25 [[nodiscard]] constexpr grapheme_iterator(code_point_iterator const &) = default;
26 [[nodiscard]] constexpr grapheme_iterator(code_point_iterator &&) = default;
27 [[nodiscard]] constexpr grapheme_iterator &operator=(code_point_iterator const &) = default;
28 [[nodiscard]] constexpr grapheme_iterator &operator=(code_point_iterator &&) = default;
29 ~grapheme_iterator() = default;
30
31 [[nodiscard]] constexpr grapheme_iterator(iterator const &it) noexcept : it(itr), forward_break_state() {}
32
33 [[nodiscard]] grapheme operator*() noexcept {
34 ttlet last_it = std::next(*this).it;
35 auto r = grapheme(it, last_it);
36 }
37
38 grapheme_iterator &operator++() noexcept
39 {
40 while (!breaks_grapheme(*(++it), forward_break_state)) {}
41 return *this;
42 }
43
44 grapheme_iterator &operator++(int) noexcept
45 {
46 auto &tmp = *this;
47 ++(*this);
48 return *this;
49 }
50
51 [[nodiscard]] friend operator==(grapheme_iterator const &lhs, grapheme_iterator const &rhs) noexcept
52 {
53 return lhs.it == rhs.it;
54 }
55
56 [[nodiscard]] friend operator<=>(grapheme_iterator const &lhs, grapheme_iterator const &rhs) noexcept
57 {
58 return lhs.it <=> rhs.it;
59 }
60
61private:
62 iterator it;
63 grapheme_break_state forward_break_state;
64};
65
66} // namespace tt
Iterate over code points (char32_t) through char8_t, char16_t or char32_t iterators.
Definition code_point_iterator.hpp:20
Definition grapheme.hpp:21
Definition grapheme_iterator.hpp:17
Definition unicode_text_segmentation.hpp:12
T next(T... args)