3 #include "fly/types/string/concepts.hpp"
4 #include "fly/types/string/detail/traits.hpp"
5 #include "fly/types/string/literals.hpp"
9 namespace fly::detail {
17 template <fly::StandardCharacter CharType>
21 using size_type =
typename traits::size_type;
22 using view_type =
typename traits::view_type;
23 using int_type =
typename traits::int_type;
36 template <fly::StandardStringLike T>
37 static constexpr size_type
size(T &&value);
46 template <std::
size_t N>
47 static constexpr size_type
size(
const CharType (&value)[N]);
61 static constexpr
bool is_alpha(CharType ch);
75 static constexpr
bool is_upper(CharType ch);
89 static constexpr
bool is_lower(CharType ch);
103 static constexpr CharType
to_upper(CharType ch);
117 static constexpr CharType
to_lower(CharType ch);
130 static constexpr
bool is_digit(CharType ch);
143 static constexpr
bool is_x_digit(CharType ch);
157 static constexpr
bool is_space(CharType ch);
168 static constexpr CharType unify_az_characters(CharType ch);
170 static constexpr
const auto s_null_terminator = FLY_CHR(CharType,
'\0');
171 static constexpr
const auto s_zero = FLY_CHR(CharType,
'0');
172 static constexpr
const auto s_upper_a = FLY_CHR(CharType,
'A');
173 static constexpr
const auto s_upper_z = FLY_CHR(CharType,
'Z');
174 static constexpr
const auto s_upper_f = FLY_CHR(CharType,
'F');
175 static constexpr
const auto s_lower_a = FLY_CHR(CharType,
'a');
176 static constexpr
const auto s_lower_z = FLY_CHR(CharType,
'z');
177 static constexpr
const auto s_space = FLY_CHR(CharType,
' ');
178 static constexpr
const auto s_form_feed = FLY_CHR(CharType,
'\f');
179 static constexpr
const auto s_line_feed = FLY_CHR(CharType,
'\n');
180 static constexpr
const auto s_carriage_return = FLY_CHR(CharType,
'\r');
181 static constexpr
const auto s_horizontal_tab = FLY_CHR(CharType,
'\t');
182 static constexpr
const auto s_vertical_tab = FLY_CHR(CharType,
'\v');
184 static constexpr
const auto s_case_bit =
static_cast<int_type
>(0x20);
185 static constexpr
const auto s_case_mask =
static_cast<int_type
>(~s_case_bit);
189 template <fly::StandardCharacter CharType>
190 template <fly::StandardStringLike T>
193 using U = std::remove_cvref_t<T>;
195 if constexpr (std::is_array_v<U> || std::is_pointer_v<U>)
197 return std::char_traits<CharType>::length(std::forward<T>(value));
206 template <fly::StandardCharacter CharType>
207 template <std::
size_t N>
210 static_assert(N > 0,
"Character arrays must have non-zero size");
211 return N - ((value[N - 1] == s_null_terminator) ? 1 : 0);
215 template <fly::StandardCharacter CharType>
218 return is_upper(unify_az_characters(ch));
222 template <fly::StandardCharacter CharType>
225 return (ch >= s_upper_a) && (ch <= s_upper_z);
229 template <fly::StandardCharacter CharType>
232 return (ch >= s_lower_a) && (ch <= s_lower_z);
236 template <fly::StandardCharacter CharType>
241 ch =
static_cast<CharType
>(
static_cast<int_type
>(ch) & s_case_mask);
248 template <fly::StandardCharacter CharType>
253 ch =
static_cast<CharType
>(
static_cast<int_type
>(ch) | s_case_bit);
260 template <fly::StandardCharacter CharType>
263 return (ch ^ s_zero) < 10;
267 template <fly::StandardCharacter CharType>
270 const auto alpha = unify_az_characters(ch);
271 return is_digit(ch) || ((alpha >= s_upper_a) && (alpha <= s_upper_f));
275 template <fly::StandardCharacter CharType>
278 return (ch == s_space) || (ch == s_form_feed) || (ch == s_line_feed) ||
279 (ch == s_carriage_return) || (ch == s_horizontal_tab) || (ch == s_vertical_tab);
283 template <fly::StandardCharacter CharType>
286 return static_cast<CharType
>(
static_cast<int_type
>(ch) & s_case_mask);
Definition: classifier.hpp:19
static constexpr bool is_digit(CharType ch)
Definition: classifier.hpp:261
static constexpr bool is_lower(CharType ch)
Definition: classifier.hpp:230
static constexpr bool is_space(CharType ch)
Definition: classifier.hpp:276
static constexpr CharType to_upper(CharType ch)
Definition: classifier.hpp:237
static constexpr CharType to_lower(CharType ch)
Definition: classifier.hpp:249
static constexpr bool is_alpha(CharType ch)
Definition: classifier.hpp:216
static constexpr bool is_x_digit(CharType ch)
Definition: classifier.hpp:268
static constexpr size_type size(T &&value)
static constexpr size_type size(const CharType(&value)[N])
static constexpr bool is_upper(CharType ch)
Definition: classifier.hpp:223
Definition: traits.hpp:18