MGL(Win32)
読み取り中…
検索中…
一致する文字列を見つけられません
mgl_text_character.h
[詳解]
1// SPDX-License-Identifier: Zlib
2/* ------------------------------------------------------------------------- */
9/* ------------------------------------------------------------------------- */
10
11#ifndef INCGUARD_MGL_TEXT_CHARACTER_H_1538587141
12#define INCGUARD_MGL_TEXT_CHARACTER_H_1538587141
13
14#include <cstddef>
15#include <cstdint>
16
19
20namespace MGL::Text
21{
24{
25public:
27 static constexpr uint32_t kInvalidMarkerBit = 1UL << 31UL;
28
30 static constexpr uint32_t kValidateMask = 0xFFFFFFFF & ~kInvalidMarkerBit;
31
33 static constexpr size_t kByteArraySize = 5;
34
35 /* ------------------------------------------------------------------------- */
40 /* ------------------------------------------------------------------------- */
41 constexpr Character(uint32_t code) noexcept
42 : _code(code)
43 {
44 }
45
46 /* ------------------------------------------------------------------------- */
51 /* ------------------------------------------------------------------------- */
52 [[nodiscard]] constexpr char32_t GetCode() const noexcept
53 {
54 return static_cast<char32_t>(_code & kValidateMask);
55 }
56
57
58 /* ------------------------------------------------------------------------- */
63 /* ------------------------------------------------------------------------- */
64 constexpr void SetCode(char32_t code) noexcept
65 {
66 _code = static_cast<uint32_t>(code);
67
68 if (_code > 0x10FFFF)
69 {
71 }
72 }
73
74
75 /* ------------------------------------------------------------------------- */
79 /* ------------------------------------------------------------------------- */
80 constexpr void SetInvalidMarker() noexcept
81 {
82 _code |= kInvalidMarkerBit;
83 }
84
85
86 /* ------------------------------------------------------------------------- */
92 /* ------------------------------------------------------------------------- */
93 [[nodiscard]] constexpr bool IsValid() const noexcept
94 {
95 return ((_code & kInvalidMarkerBit) == 0);
96 }
97
98
99 /* ------------------------------------------------------------------------- */
105 /* ------------------------------------------------------------------------- */
106 [[nodiscard]] constexpr bool IsNull() const noexcept
107 {
108 return (GetCode() == 0);
109 }
110
111
112 /* ------------------------------------------------------------------------- */
118 /* ------------------------------------------------------------------------- */
119 [[nodiscard]] constexpr bool IsNewLine() const noexcept
120 {
121 return ((_code == 0x0D) || (_code == 0x0A));
122 }
123
124
125 /* ------------------------------------------------------------------------- */
131 /* ------------------------------------------------------------------------- */
132 [[nodiscard]] constexpr bool IsSpace() const noexcept
133 {
134 return ((_code == ' ') || (_code == '\t'));
135 }
136
137
138 /* ------------------------------------------------------------------------- */
142 /* ------------------------------------------------------------------------- */
143 [[nodiscard]] constexpr bool IsDigit() const noexcept
144 {
145 return ((_code >= '0') && (_code <= '9'));
146 }
147
148 [[nodiscard]] size_t GetByteSize() const noexcept;
149 bool ToByte(char byteArray[kByteArraySize]) const noexcept;
150 char *ToByte(char *dest, size_t destSize) const noexcept;
151 [[nodiscard]] STL::string ToString() const noexcept;
152
153private:
154 uint32_t _code;
155};
156
157
159class CharacterArray : public STL::vector<Character>
160{
161public:
162 [[nodiscard]] STL::string ToString() const;
163 [[nodiscard]] STL::string ToString(uint32_t start, uint32_t end) const;
164
165 [[nodiscard]] int Find(uint32_t findCode, uint32_t start = 0) const;
166
167 /* ------------------------------------------------------------------------- */
175 /* ------------------------------------------------------------------------- */
176 reference at(size_type n)
177 {
178 return (n >= size()) ? _endCode : STL::vector<Character>::at(n);
179 }
180
181 /* ------------------------------------------------------------------------- */
189 /* ------------------------------------------------------------------------- */
190 [[nodiscard]] const_reference at(size_type n) const
191 {
192 return (n >= size()) ? _endCode : STL::vector<Character>::at(n);
193 }
194
195 /* ------------------------------------------------------------------------- */
203 /* ------------------------------------------------------------------------- */
204 [[nodiscard]] reference operator[](size_type pos) noexcept
205 {
206 return CharacterArray::at(pos);
207 }
208
209 /* ------------------------------------------------------------------------- */
217 /* ------------------------------------------------------------------------- */
218 [[nodiscard]] const_reference operator[](size_type pos) const noexcept
219 {
220 return CharacterArray::at(pos);
221 }
222
223private:
224 inline static Character _endCode{'\0'};
225};
226} // namespace MGL::Text
227
228#endif // INCGUARD_MGL_TEXT_CHARACTER_H_1538587141
229
230// vim: et ts=4 sw=4 sts=4
231
文字の集合体クラス
Definition mgl_text_character.h:160
reference operator[](size_type pos) noexcept
配列アクセス
Definition mgl_text_character.h:204
reference at(size_type n)
STL::vector::atのオーバーライド
Definition mgl_text_character.h:176
const_reference operator[](size_type pos) const noexcept
配列アクセス(const版)
Definition mgl_text_character.h:218
const_reference at(size_type n) const
STL::vector::atのオーバーライド(const版)
Definition mgl_text_character.h:190
文字クラス
Definition mgl_text_character.h:24
static constexpr uint32_t kValidateMask
コードの有効範囲
Definition mgl_text_character.h:30
constexpr void SetInvalidMarker() noexcept
不正なコードのマーカーを書き込む
Definition mgl_text_character.h:80
STL::string ToString() const noexcept
文字をSTL::stringに変換
Definition mgl_text_character.cc:195
static constexpr size_t kByteArraySize
バイト配列のサイズ
Definition mgl_text_character.h:33
constexpr bool IsDigit() const noexcept
数値かどうかを取得
Definition mgl_text_character.h:143
constexpr bool IsNull() const noexcept
Null文字かどうかを判定
Definition mgl_text_character.h:106
constexpr bool IsValid() const noexcept
コードが正常かどうかを取得する
Definition mgl_text_character.h:93
constexpr void SetCode(char32_t code) noexcept
値を設定
Definition mgl_text_character.h:64
constexpr Character(uint32_t code) noexcept
コンストラクタ
Definition mgl_text_character.h:41
constexpr char32_t GetCode() const noexcept
値を取得
Definition mgl_text_character.h:52
constexpr bool IsNewLine() const noexcept
改行文字かどうかを取得
Definition mgl_text_character.h:119
static constexpr uint32_t kInvalidMarkerBit
不正な文字を検出した際に書き込むビット位置
Definition mgl_text_character.h:27
size_t GetByteSize() const noexcept
文字をバイトに変換する際に必要なサイズを取得
Definition mgl_text_character.cc:23
constexpr bool IsSpace() const noexcept
スペースかどうかを取得
Definition mgl_text_character.h:132
bool ToByte(char byteArray[kByteArraySize]) const noexcept
コードをバイト列に変換
Definition mgl_text_character.cc:141
MGL STLコンテナの代替
std::vector< T, Allocator< T > > vector
std::vectorの代替
Definition mgl_stl_containers.h:51
MGL STL文字列クラスの代替
basic_string< char > string
std::stringの代替
Definition mgl_stl_string.h:25