tetengo 1.8.2
A multipurpose library set
Loading...
Searching...
No Matches
grapheme_splitter.hpp
Go to the documentation of this file.
1
7#if !defined(TETENGO_TEXT_GRAPHEMESPLITTER_HPP)
8#define TETENGO_TEXT_GRAPHEMESPLITTER_HPP
9
10#include <cstddef>
11#include <locale>
12#include <memory>
13#include <string_view>
14#include <vector>
15
16#include <boost/core/noncopyable.hpp>
17#include <boost/operators.hpp>
18
19
20namespace tetengo::text
21{
25 class grapheme : public boost::equality_comparable<grapheme>
26 {
27 public:
28 // constructors and destructor
29
36 constexpr grapheme(std::size_t offset, std::size_t width) : m_offset{ offset }, m_width{ width } {}
37
38
39 // functions
40
50 [[nodiscard]] friend constexpr bool operator==(const grapheme& one, const grapheme& another)
51 {
52 return one.m_offset == another.m_offset && one.m_width == another.m_width;
53 }
54
60 [[nodiscard]] constexpr std::size_t offset() const
61 {
62 return m_offset;
63 }
64
70 [[nodiscard]] constexpr std::size_t width() const
71 {
72 return m_width;
73 }
74
75
76 private:
77 // variables
78
79 std::size_t m_offset;
80
81 std::size_t m_width;
82 };
83
84
88 class grapheme_splitter : private boost::noncopyable
89 {
90 public:
91 // constructors and destructor
92
98 explicit grapheme_splitter(const std::locale& locale_ = std::locale{ "" });
99
104
105
106 // functions
107
124 [[nodiscard]] std::vector<grapheme> split(const std::string_view& string_) const;
125
126
127 private:
128 // types
129
130 class impl;
131
132
133 // variables
134
135 const std::unique_ptr<impl> m_p_impl;
136 };
137
138
139}
140
141
142#endif
A grapheme splitter.
Definition grapheme_splitter.hpp:89
virtual ~grapheme_splitter()
Destroys the grapheme splitter.
grapheme_splitter(const std::locale &locale_=std::locale{ "" })
Creates a grapheme splitter.
std::vector< grapheme > split(const std::string_view &string_) const
Split a string to graphemes.
A grapheme.
Definition grapheme_splitter.hpp:26
constexpr std::size_t width() const
Returns the width when using a monospace font.
Definition grapheme_splitter.hpp:70
friend constexpr bool operator==(const grapheme &one, const grapheme &another)
Returns true when one grapheme is equal to another.
Definition grapheme_splitter.hpp:50
constexpr std::size_t offset() const
Returns the offset in the UTF-8 string.
Definition grapheme_splitter.hpp:60
constexpr grapheme(std::size_t offset, std::size_t width)
Creates a grapheme.
Definition grapheme_splitter.hpp:36
A text library.