@@ -14,12 +14,13 @@ namespace fly::detail {
14
14
* @author Timothy Flynn ([email protected] )
15
15
* @version January 3, 2021
16
16
*/
17
- template <typename StringType >
18
- class BasicStringClassifier
17
+ template <typename CharType >
18
+ class BasicClassifier
19
19
{
20
- using traits = detail::BasicStringTraits<StringType>;
20
+ using string_type = std::basic_string<CharType>;
21
+
22
+ using traits = detail::BasicStringTraits<string_type>;
21
23
using size_type = typename traits::size_type;
22
- using char_type = typename traits::char_type;
23
24
using view_type = typename traits::view_type;
24
25
using int_type = typename traits::int_type;
25
26
@@ -45,7 +46,7 @@ class BasicStringClassifier
45
46
* @return The length of the character array.
46
47
*/
47
48
template <std::size_t N>
48
- static constexpr size_type size (const char_type (&value)[N]);
49
+ static constexpr size_type size (const CharType (&value)[N]);
49
50
50
51
/* *
51
52
* Checks if the given character is an alphabetic character as classified by the default C
@@ -59,7 +60,7 @@ class BasicStringClassifier
59
60
*
60
61
* @return True if the character is an alphabetic character.
61
62
*/
62
- static constexpr bool is_alpha (char_type ch);
63
+ static constexpr bool is_alpha (CharType ch);
63
64
64
65
/* *
65
66
* Checks if the given character is an upper-case alphabetic character as classified by the
@@ -73,7 +74,7 @@ class BasicStringClassifier
73
74
*
74
75
* @return True if the character is an alphabetic character.
75
76
*/
76
- static constexpr bool is_upper (char_type ch);
77
+ static constexpr bool is_upper (CharType ch);
77
78
78
79
/* *
79
80
* Checks if the given character is a lower-case alphabetic character as classified by the
@@ -87,7 +88,7 @@ class BasicStringClassifier
87
88
*
88
89
* @return True if the character is an alphabetic character.
89
90
*/
90
- static constexpr bool is_lower (char_type ch);
91
+ static constexpr bool is_lower (CharType ch);
91
92
92
93
/* *
93
94
* Converts the given character to an upper-case alphabetic character as classified by the
@@ -101,7 +102,7 @@ class BasicStringClassifier
101
102
*
102
103
* @return The converted character.
103
104
*/
104
- static constexpr char_type to_upper (char_type ch);
105
+ static constexpr CharType to_upper (CharType ch);
105
106
106
107
/* *
107
108
* Converts the given character to a lower-case alphabetic character as classified by the
@@ -115,7 +116,7 @@ class BasicStringClassifier
115
116
*
116
117
* @return The converted character.
117
118
*/
118
- static constexpr char_type to_lower (char_type ch);
119
+ static constexpr CharType to_lower (CharType ch);
119
120
120
121
/* *
121
122
* Checks if the given character is a decimal digit character.
@@ -128,7 +129,7 @@ class BasicStringClassifier
128
129
*
129
130
* @return True if the character is a decimal digit character.
130
131
*/
131
- static constexpr bool is_digit (char_type ch);
132
+ static constexpr bool is_digit (CharType ch);
132
133
133
134
/* *
134
135
* Checks if the given character is a hexadecimal digit character.
@@ -141,7 +142,7 @@ class BasicStringClassifier
141
142
*
142
143
* @return True if the character is a hexadecimal digit character.
143
144
*/
144
- static constexpr bool is_x_digit (char_type ch);
145
+ static constexpr bool is_x_digit (CharType ch);
145
146
146
147
/* *
147
148
* Checks if the given character is a whitespace character as classified by the default C
@@ -155,7 +156,7 @@ class BasicStringClassifier
155
156
*
156
157
* @return True if the character is a whitespace character.
157
158
*/
158
- static constexpr bool is_space (char_type ch);
159
+ static constexpr bool is_space (CharType ch);
159
160
160
161
private:
161
162
/* *
@@ -166,125 +167,125 @@ class BasicStringClassifier
166
167
*
167
168
* @return The modified character.
168
169
*/
169
- static constexpr char_type unify_az_characters (char_type ch);
170
-
171
- static constexpr const auto s_null_terminator = FLY_CHR(char_type , ' \0 ' );
172
- static constexpr const auto s_zero = FLY_CHR(char_type , ' 0' );
173
- static constexpr const auto s_upper_a = FLY_CHR(char_type , ' A' );
174
- static constexpr const auto s_upper_z = FLY_CHR(char_type , ' Z' );
175
- static constexpr const auto s_upper_f = FLY_CHR(char_type , ' F' );
176
- static constexpr const auto s_lower_a = FLY_CHR(char_type , ' a' );
177
- static constexpr const auto s_lower_z = FLY_CHR(char_type , ' z' );
178
- static constexpr const auto s_space = FLY_CHR(char_type , ' ' );
179
- static constexpr const auto s_form_feed = FLY_CHR(char_type , ' \f ' );
180
- static constexpr const auto s_line_feed = FLY_CHR(char_type , ' \n ' );
181
- static constexpr const auto s_carriage_return = FLY_CHR(char_type , ' \r ' );
182
- static constexpr const auto s_horizontal_tab = FLY_CHR(char_type , ' \t ' );
183
- static constexpr const auto s_vertical_tab = FLY_CHR(char_type , ' \v ' );
170
+ static constexpr CharType unify_az_characters (CharType ch);
171
+
172
+ static constexpr const auto s_null_terminator = FLY_CHR(CharType , ' \0 ' );
173
+ static constexpr const auto s_zero = FLY_CHR(CharType , ' 0' );
174
+ static constexpr const auto s_upper_a = FLY_CHR(CharType , ' A' );
175
+ static constexpr const auto s_upper_z = FLY_CHR(CharType , ' Z' );
176
+ static constexpr const auto s_upper_f = FLY_CHR(CharType , ' F' );
177
+ static constexpr const auto s_lower_a = FLY_CHR(CharType , ' a' );
178
+ static constexpr const auto s_lower_z = FLY_CHR(CharType , ' z' );
179
+ static constexpr const auto s_space = FLY_CHR(CharType , ' ' );
180
+ static constexpr const auto s_form_feed = FLY_CHR(CharType , ' \f ' );
181
+ static constexpr const auto s_line_feed = FLY_CHR(CharType , ' \n ' );
182
+ static constexpr const auto s_carriage_return = FLY_CHR(CharType , ' \r ' );
183
+ static constexpr const auto s_horizontal_tab = FLY_CHR(CharType , ' \t ' );
184
+ static constexpr const auto s_vertical_tab = FLY_CHR(CharType , ' \v ' );
184
185
185
186
static constexpr const auto s_case_bit = static_cast <int_type>(0x20 );
186
187
static constexpr const auto s_case_mask = static_cast <int_type>(~s_case_bit);
187
188
};
188
189
189
190
// ==================================================================================================
190
- template <typename StringType >
191
+ template <typename CharType >
191
192
template <typename T, enable_if<detail::is_like_supported_string<T>>>
192
- constexpr inline auto BasicStringClassifier<StringType >::size(T &&value) -> size_type
193
+ constexpr inline auto BasicClassifier<CharType >::size(T &&value) -> size_type
193
194
{
194
- if constexpr (any_same_v<T, StringType, view_type>)
195
+ using U = std::remove_cvref_t <T>;
196
+
197
+ if constexpr (std::is_array_v<U> || std::is_pointer_v<U>)
195
198
{
196
- return value. size ( );
199
+ return std::char_traits<CharType>:: length (std::forward<T>(value) );
197
200
}
198
201
else
199
202
{
200
- return std::char_traits<char_type>:: length (std::forward<T>( value) );
203
+ return value. size ( );
201
204
}
202
205
}
203
206
204
207
// ==================================================================================================
205
- template <typename StringType >
208
+ template <typename CharType >
206
209
template <std::size_t N>
207
- constexpr inline auto BasicStringClassifier<StringType>::size(const char_type (&value)[N])
208
- -> size_type
210
+ constexpr inline auto BasicClassifier<CharType>::size(const CharType (&value)[N]) -> size_type
209
211
{
210
212
static_assert (N > 0 , " Character arrays must have non-zero size" );
211
213
return N - ((value[N - 1 ] == s_null_terminator) ? 1 : 0 );
212
214
}
213
215
214
216
// ==================================================================================================
215
- template <typename StringType >
216
- constexpr inline bool BasicStringClassifier<StringType >::is_alpha(char_type ch)
217
+ template <typename CharType >
218
+ constexpr inline bool BasicClassifier<CharType >::is_alpha(CharType ch)
217
219
{
218
220
return is_upper (unify_az_characters (ch));
219
221
}
220
222
221
223
// ==================================================================================================
222
- template <typename StringType >
223
- constexpr inline bool BasicStringClassifier<StringType >::is_upper(char_type ch)
224
+ template <typename CharType >
225
+ constexpr inline bool BasicClassifier<CharType >::is_upper(CharType ch)
224
226
{
225
227
return (ch >= s_upper_a) && (ch <= s_upper_z);
226
228
}
227
229
228
230
// ==================================================================================================
229
- template <typename StringType >
230
- constexpr inline bool BasicStringClassifier<StringType >::is_lower(char_type ch)
231
+ template <typename CharType >
232
+ constexpr inline bool BasicClassifier<CharType >::is_lower(CharType ch)
231
233
{
232
234
return (ch >= s_lower_a) && (ch <= s_lower_z);
233
235
}
234
236
235
237
// ==================================================================================================
236
- template <typename StringType >
237
- constexpr inline auto BasicStringClassifier<StringType >::to_upper(char_type ch) -> char_type
238
+ template <typename CharType >
239
+ constexpr inline CharType BasicClassifier<CharType >::to_upper(CharType ch)
238
240
{
239
241
if (is_lower (ch))
240
242
{
241
- ch = static_cast <char_type >(static_cast <int_type>(ch) & s_case_mask);
243
+ ch = static_cast <CharType >(static_cast <int_type>(ch) & s_case_mask);
242
244
}
243
245
244
246
return ch;
245
247
}
246
248
247
249
// ==================================================================================================
248
- template <typename StringType >
249
- constexpr inline auto BasicStringClassifier<StringType >::to_lower(char_type ch) -> char_type
250
+ template <typename CharType >
251
+ constexpr inline CharType BasicClassifier<CharType >::to_lower(CharType ch)
250
252
{
251
253
if (is_upper (ch))
252
254
{
253
- ch = static_cast <char_type >(static_cast <int_type>(ch) | s_case_bit);
255
+ ch = static_cast <CharType >(static_cast <int_type>(ch) | s_case_bit);
254
256
}
255
257
256
258
return ch;
257
259
}
258
260
259
261
// ==================================================================================================
260
- template <typename StringType >
261
- constexpr inline bool BasicStringClassifier<StringType >::is_digit(char_type ch)
262
+ template <typename CharType >
263
+ constexpr inline bool BasicClassifier<CharType >::is_digit(CharType ch)
262
264
{
263
265
return (ch ^ s_zero) < 10 ;
264
266
}
265
267
266
268
// ==================================================================================================
267
- template <typename StringType >
268
- constexpr inline bool BasicStringClassifier<StringType >::is_x_digit(char_type ch)
269
+ template <typename CharType >
270
+ constexpr inline bool BasicClassifier<CharType >::is_x_digit(CharType ch)
269
271
{
270
272
const auto alpha = unify_az_characters (ch);
271
273
return is_digit (ch) || ((alpha >= s_upper_a) && (alpha <= s_upper_f));
272
274
}
273
275
274
276
// ==================================================================================================
275
- template <typename StringType >
276
- constexpr inline bool BasicStringClassifier<StringType >::is_space(char_type ch)
277
+ template <typename CharType >
278
+ constexpr inline bool BasicClassifier<CharType >::is_space(CharType ch)
277
279
{
278
280
return (ch == s_space) || (ch == s_form_feed) || (ch == s_line_feed) ||
279
281
(ch == s_carriage_return) || (ch == s_horizontal_tab) || (ch == s_vertical_tab);
280
282
}
281
283
282
284
// ==================================================================================================
283
- template <typename StringType>
284
- constexpr inline auto BasicStringClassifier<StringType>::unify_az_characters(char_type ch)
285
- -> char_type
285
+ template <typename CharType>
286
+ constexpr inline CharType BasicClassifier<CharType>::unify_az_characters(CharType ch)
286
287
{
287
- return static_cast <char_type >(static_cast <int_type>(ch) & s_case_mask);
288
+ return static_cast <CharType >(static_cast <int_type>(ch) & s_case_mask);
288
289
}
289
290
290
291
} // namespace fly::detail
0 commit comments