acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
utf8_character.h
1// Created by camilo on 2022-11-10 22:40 <3ThomasBorregaardSorensen!!
2#pragma once
3
4
5#include "inline_string.h"
6
7
8class CLASS_DECL_ACME utf8_character :
9 public inline_string < ::ansi_character, 8 >
10{
11public:
12
13
14 mutable ::i64 m_llIndex = -1;
15
16
17 utf8_character() {}
18 utf8_character(::i64 ch);
19
20
21 character_count get_next(const character_range < const_char_pointer >& range, character_count charactercount);
22
23
24 ::i64 index() const;
25
26 bool operator == (ansi_character ansicharacter) const
27 {
28
29 if (ansicharacter < 0)
30 {
31
32 throw ::exception(error_bad_argument);
33
34 }
35
36 auto llIndex = index();
37
38 return ansicharacter == llIndex;
39
40 }
41
42
43 ansi_character ansi_lower() const
44 {
45
46 auto llIndex = index();
47
48 if (llIndex >= 128)
49 {
50
51 throw ::exception(error_wrong_state, "not an ansi character");
52
53 }
54
55 return character_tolower((ansi_character)llIndex);
56
57 }
58
59
60 ansi_character ansi_uppwer() const
61 {
62
63 auto llIndex = index();
64
65 if (llIndex >= 128)
66 {
67
68 throw ::exception(error_wrong_state, "not an ansi character");
69
70 }
71
72 return character_toupper((ansi_character)llIndex);
73
74 }
75
76 bool is_space() const
77 {
78
79 return wd32_char_isspace((wd32_character) index());
80
81 }
82
83 bool is_ansi_space() const
84 {
85
86 auto llIndex = index();
87
88 if (llIndex >= 128)
89 {
90
91 return false;
92
93 }
94
95 return character_isspace((ansi_character)llIndex);
96
97 }
98
99
100 bool is_ansi_alpha() const
101 {
102
103 auto llIndex = index();
104
105 if (llIndex >= 128)
106 {
107
108 return false;
109
110 }
111
112 return character_isalpha((ansi_character)llIndex);
113
114 }
115
116
117 bool is_ansi_digit() const
118 {
119
120 auto llIndex = index();
121
122 if (llIndex >= 128)
123 {
124
125 return false;
126
127 }
128
129 return character_isdigit((ansi_character)llIndex);
130
131 }
132
133 bool is_ansi_alpha_or_digit() const
134 {
135
136 auto llIndex = index();
137
138 if (llIndex >= 128)
139 {
140
141 return false;
142
143 }
144
145 return character_isalpha((ansi_character)llIndex)
146 || character_isdigit((ansi_character)llIndex);
147 }
148
149};
150
151
152class CLASS_DECL_ACME utf8_character_range :
153 public utf8_character
154{
155public:
156
157
158 character_range < const_char_pointer >& m_range;
159
160 character_count m_i32;
161
162 character_count m_iNext;
163
164 utf8_character_range(const utf8_character_range& range) :
165 m_range(range.m_range),
166 m_i32(range.m_i32),
167 m_iNext(range.m_i32)
168 {
169 this->m_begin = range.m_begin;
170 this->m_end = range.m_end;
171 this->m_erange = range.m_erange;
172 this->m_llIndex = -1;
173 memory_copy(m_sz, range.m_sz, sizeof(m_sz));
174
175
176 }
177
178 utf8_character_range(character_range < const_char_pointer >& range, character_count i = 0) :
179 m_range(range)
180 {
181
182 m_i32 = i;
183
184 this->m_llIndex = -1;
185
186 get();
187
188 }
189
190 utf8_character_range& get()
191 {
192
193 if (m_llIndex < 0)
194 {
195
196 m_iNext = ::utf8_character::get_next(m_range, m_i32);
197
198 this->index();
199
200 }
201
202 return *this;
203
204 }
205
206
207 utf8_character_range& operator++()
208 {
209
210 m_i32 = m_iNext;
211
212 m_llIndex = -1;
213
214 get();
215
216 return *this;
217
218 }
219
220
221 utf8_character_range operator++(::i32)
222 {
223
224 utf8_character_range ret = *this;
225
226 ++(*this);
227
228 return ret;
229
230 }
231
232
233 utf8_character_range & operator+=(character_count count)
234 {
235
236 auto c = count;
237
238 while (c > 0)
239 {
240
241 ++(*this);
242
243 c--;
244
245 }
246
247 return *this;
248
249 }
250
251
252 utf8_character_range& ansi_add(character_count count)
253 {
254
255 m_i32 += count;
256
257 m_llIndex = -1;
258
259 this->get();
260
261 return *this;
262
263 }
264
265
266
267
268
269
270 utf8_character_range next() const
271 {
272
273 return { m_range, m_iNext };
274
275 }
276
277
278
279 using utf8_character::operator == ;
280
281
282
283};
Definition range.h:223