1#ifndef MSTL_CORE_STRING_CHAR_TYPES_HPP__
2#define MSTL_CORE_STRING_CHAR_TYPES_HPP__
30MSTL_INLINE17
constexpr uint64_t BLANK_MASK =
40MSTL_INLINE17
constexpr uint64_t SPACE_MASK =
53MSTL_INLINE17
constexpr uint64_t PUNCT_MASK_LOW =
54 (1ULL << 33) | (1ULL << 34) | (1ULL << 35) | (1ULL << 36) |
55 (1ULL << 37) | (1ULL << 38) | (1ULL << 39) | (1ULL << 40) |
56 (1ULL << 41) | (1ULL << 42) | (1ULL << 43) | (1ULL << 44) |
57 (1ULL << 45) | (1ULL << 46) | (1ULL << 47) | (1ULL << 58) |
58 (1ULL << 59) | (1ULL << 60) | (1ULL << 61) | (1ULL << 62) |
67MSTL_INLINE17
constexpr uint64_t PUNCT_MASK_HIGH =
68 (1ULL << (64 - 64)) | (1ULL << (65 - 64)) | (1ULL << (91 - 64)) |
69 (1ULL << (92 - 64)) | (1ULL << (93 - 64)) | (1ULL << (94 - 64)) |(1ULL << (95 - 64)) |
70 (1ULL << (96 - 64)) | (1ULL << (123 - 64)) | (1ULL << (124 - 64)) | (1ULL << (125 - 64)) |
79MSTL_INLINE17
constexpr uint64_t CNTRL_MASK_LOW =
80 (1ULL << 0) | (1ULL << 1) | (1ULL << 2) | (1ULL << 3) |
81 (1ULL << 4) | (1ULL << 5) | (1ULL << 6) | (1ULL << 7) |
82 (1ULL << 8) | (1ULL << 9) | (1ULL << 10) | (1ULL << 11) |
83 (1ULL << 12) | (1ULL << 13) | (1ULL << 14) | (1ULL << 15) |
84 (1ULL << 16) | (1ULL << 17) | (1ULL << 18) | (1ULL << 19) |
85 (1ULL << 20) | (1ULL << 21) | (1ULL << 22) | (1ULL << 23) |
86 (1ULL << 24) | (1ULL << 25) | (1ULL << 26) | (1ULL << 27) |
87 (1ULL << 28) | (1ULL << 29) | (1ULL << 30) | (1ULL << 31);
95MSTL_INLINE17
constexpr uint64_t CNTRL_MASK_HIGH =
112template <
typename CharT>
114 static_assert(is_character_v<CharT>,
"character type is necessary");
116 if (uc > 127)
return false;
117 if (uc <= 63)
return (mask_low & (1ULL << uc)) != 0;
118 const auto offset = uc - 64;
119 return (mask_high & (1ULL << offset)) != 0;
128template <
typename CharT>
129MSTL_PURE_FUNCTION MSTL_CONSTEXPR14
bool is_punct(
const CharT c)
noexcept {
141template <
typename CharT>
142MSTL_PURE_FUNCTION MSTL_CONSTEXPR14
bool is_cntrl(
const CharT c)
noexcept {
154template <
typename CharT>
155MSTL_PURE_FUNCTION MSTL_CONSTEXPR14
bool is_print(
const CharT c)
noexcept {
156 static_assert(is_character_v<CharT>,
"character type is necessary");
169template <
typename CharT>
170MSTL_PURE_FUNCTION MSTL_CONSTEXPR14
bool is_blank(
const CharT c)
noexcept {
171 static_assert(is_character_v<CharT>,
"character type is necessary");
173 return uc < 64 && (
_CONSTANTS BLANK_MASK & (1ULL << uc)) != 0;
184template <
typename CharT>
185MSTL_PURE_FUNCTION MSTL_CONSTEXPR14
bool is_graph(
const CharT c)
noexcept {
197template <
typename CharT>
198MSTL_CONST_FUNCTION MSTL_CONSTEXPR14
bool is_ascii(
const CharT c)
noexcept {
199 static_assert(is_character_v<CharT>,
"character type is necessary");
212template <
typename CharT>
213MSTL_PURE_FUNCTION MSTL_CONSTEXPR14
bool is_space(
const CharT c)
noexcept {
214 static_assert(is_character_v<CharT>,
"character type is necessary");
216 return uc < 64 && (
_CONSTANTS SPACE_MASK & (1ULL << uc)) != 0;
227template <
typename CharT>
228MSTL_CONST_FUNCTION MSTL_CONSTEXPR14
bool is_alpha(
const CharT c)
noexcept {
229 static_assert(is_character_v<CharT>,
"character type is necessary");
231 if (uc > 127)
return false;
232 return (uc & 0xDF) >=
'A' && (uc & 0xDF) <=
'Z';
243template <
typename CharT>
244MSTL_CONST_FUNCTION MSTL_CONSTEXPR14
bool is_digit(
const CharT c)
noexcept {
245 static_assert(is_character_v<CharT>,
"character type is necessary");
247 if (uc > 127)
return false;
248 return (uc & 0xF0) == 0x30 && (uc & 0x0F) <= 9;
259template <
typename CharT>
260MSTL_CONST_FUNCTION MSTL_CONSTEXPR14
bool is_xdigit(
const CharT c)
noexcept {
261 static_assert(is_character_v<CharT>,
"character type is necessary");
263 if (uc > 127)
return false;
264 const bool is_09 = (uc & 0xF0) == 0x30 && (uc & 0x0F) <= 0x09;
265 const bool is_AF = (uc & 0xF0) == 0x40 && (uc & 0x0F) >= 0x01 && (uc & 0x0F) <= 0x06;
266 const bool is_af = (uc & 0xF0) == 0x60 && (uc & 0x0F) >= 0x01 && (uc & 0x0F) <= 0x06;
267 return is_09 || is_AF || is_af;
276template <
typename CharT>
287template <
typename CharT>
308 return c >= 0xD800 && c <= 0xDBFF;
319 return c >= 0xDC00 && c <= 0xDFFF;
331 return 0x10000 + ((
static_cast<uint32_t>(high) - 0xD800) << 10) + (
static_cast<uint32_t>(low) - 0xDC00);
MSTL_PURE_FUNCTION MSTL_CONSTEXPR14 bool is_blank(const CharT c) noexcept
检查字符是否为空白字符
MSTL_PURE_FUNCTION MSTL_CONSTEXPR14 bool is_graph(const CharT c) noexcept
检查字符是否为图形字符
MSTL_PURE_FUNCTION MSTL_CONSTEXPR14 bool is_cntrl(const CharT c) noexcept
检查字符是否为控制字符
MSTL_CONST_FUNCTION MSTL_CONSTEXPR14 bool is_ascii(const CharT c) noexcept
检查字符是否为ASCII字符
MSTL_CONST_FUNCTION MSTL_CONSTEXPR14 bool is_digit_or_alpha(const CharT c) noexcept
检查字符是否为数字或字母
MSTL_CONST_FUNCTION MSTL_CONSTEXPR14 bool is_alpha(const CharT c) noexcept
检查字符是否为字母
MSTL_PURE_FUNCTION MSTL_CONSTEXPR14 bool is_print(const CharT c) noexcept
检查字符是否为可打印字符
MSTL_PURE_FUNCTION MSTL_CONSTEXPR14 bool is_ctype(const CharT c, uint64_t mask_low, uint64_t mask_high) noexcept
通用字符类型检查函数
MSTL_PURE_FUNCTION MSTL_CONSTEXPR14 bool is_space(const CharT c) noexcept
检查字符是否为空白字符
MSTL_PURE_FUNCTION MSTL_CONSTEXPR14 bool is_punct(const CharT c) noexcept
检查字符是否为标点符号
MSTL_CONST_FUNCTION MSTL_CONSTEXPR14 bool is_alpha_or_digit(const CharT c) noexcept
检查字符是否为字母或数字
MSTL_CONST_FUNCTION MSTL_CONSTEXPR14 bool is_digit(const CharT c) noexcept
检查字符是否为数字
MSTL_CONST_FUNCTION MSTL_CONSTEXPR14 bool is_xdigit(const CharT c) noexcept
检查字符是否为十六进制数字
unsigned int uint32_t
32位无符号整数类型
unsigned long long uint64_t
64位无符号整数类型
#define _MSTL
全局命名空间MSTL前缀
#define MSTL_END_CONSTANTS__
结束constants命名空间
#define _CONSTANTS
constants命名空间前缀
#define MSTL_BEGIN_CONSTANTS__
开始constants命名空间
#define MSTL_END_NAMESPACE__
结束全局命名空间MSTL
#define MSTL_BEGIN_NAMESPACE__
开始全局命名空间MSTL
typename make_unsigned< T >::type make_unsigned_t
make_unsigned的便捷别名
MSTL_CONST_FUNCTION constexpr bool is_high_surrogate(const char16_t c) noexcept
检查字符是否为高代理项
MSTL_CONST_FUNCTION constexpr bool is_low_surrogate(const char16_t c) noexcept
检查字符是否为低代理项
MSTL_CONST_FUNCTION constexpr uint32_t combine_surrogates(const char16_t high, const char16_t low) noexcept
组合高代理项和低代理项为完整的Unicode码点