YSTest: cctype.h 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

cctype.h
浏览该文件的文档.
1 /*
2 © 2014-2016, 2018-2020 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
28 #ifndef YB_INC_ystdex_cctype_h_
29 #define YB_INC_ystdex_cctype_h_ 1
30
31 #include "../ydef.h" // for yconstfn, CHAR_MIN, yimpl;
32 #include <cwctype> // for std::towlower, std::towupper;
33 #include <cctype> // for std::tolower, std::toupper;
34
35 namespace ystdex
36 {
37
47 YB_ATTR_nodiscard YB_STATELESS yconstfn bool
49 iscntrl_C0(char c) ynothrow
50 {
51 #if CHAR_MIN < 0
52 return c >= 0 && c < 0x20;
53 #else
54 return c < 0x20;
55 #endif
56 }
57
59 YB_ATTR_nodiscard YB_STATELESS yconstfn bool
60 iscntrl_C1(char c) ynothrow
61 {
62 return (unsigned(c) & 0xFFU) >= 0x80 && (unsigned(c) & 0xFFU) < 0xA0;
63 }
64
69 YB_ATTR_nodiscard YB_STATELESS yconstfn bool
70 iscntrl_ASCII(char c) ynothrow
71 {
72 return iscntrl_C0(c) || c == 0x7F;
73 }
74
76 YB_ATTR_nodiscard YB_STATELESS yconstfn bool
77 iscntrl_ISO8859_11(char c) ynothrow
78 {
79 return iscntrl_C0(c)
80 || ((unsigned(c) & 0xFFU) >= 0x7F && (unsigned(c) & 0xFFU) <= 0xA0);
81 }
82
84 YB_ATTR_nodiscard YB_STATELESS yconstfn bool
85 iscntrl_ISO8859_1(char c) ynothrow
86 {
87 return iscntrl_ISO8859_11(c) || (unsigned(c) & 0xFFU) == 0xAD;
88 }
89
90
95 YB_ATTR_nodiscard YB_STATELESS yconstfn bool
96 isprint_ASCII(char c) ynothrow
97 {
98 return c >= 0x20 && c < 0x7F;
99 }
100
102 YB_ATTR_nodiscard YB_STATELESS yconstfn bool
103 isprint_ISO8859_1(char c) ynothrow
104 {
105 return isprint_ASCII(c) || unsigned(c) > 0xA0;
106 }
107
114 YB_ATTR_nodiscard YB_STATELESS yconstfn bool
115 isprint(char c) ynothrow
116 {
117 return yimpl(isprint_ISO8859_1(c));
118 }
119
128 YB_ATTR_nodiscard YB_STATELESS yconstfn bool
129 isdigit(char c) ynothrow
130 {
131 return (unsigned(c) - '0') < 10U;
132 }
133
139 YB_ATTR_nodiscard YB_STATELESS yconstfn bool
140 isspace(char c) ynothrow
141 {
142 return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == '\v';
143 }
144
145
152 YB_ATTR_nodiscard inline char
153 tolower(char c) ynothrow
154 {
155 #if CHAR_MIN < 0
156 return c >= 0 ? char(std::tolower(c)) : c;
157 #else
158 return char(std::tolower(c));
159 #endif
160 }
161
163 template<typename _tChar>
164 YB_ATTR_nodiscard inline _tChar
165 towlower(_tChar c) ynothrow
166 {
167 return c >= 0 ? _tChar(std::towlower(wint_t(c))) : c;
168 }
169
170
171 YB_ATTR_nodiscard inline char
172 toupper(char c) ynothrow
173 {
174 #if CHAR_MIN < 0
175 return c >= 0 ? char(std::toupper(c)) : c;
176 #else
177 return char(std::toupper(c));
178 #endif
179 }
180
182 template<typename _tChar>
183 YB_ATTR_nodiscard inline _tChar
184 towupper(_tChar c) ynothrow
185 {
186 return c >= 0 ? _tChar(std::towupper(wint_t(c))) : c;
187 }
189
190
191 } // namespace ystdex;
192
193 #endif
194
YB_ATTR_nodiscard
#define YB_ATTR_nodiscard
标记返回值不被忽略的属性。
Definition: ydef.h:715
ystdex::isprint
bool isprint(char c)
区域无关的 std::isprint 。
Definition: cctype.h:115
CHRLib::c
c
Definition: CharacterProcessing.h:84
ystdex::towlower
_tChar towlower(_tChar c)
Definition: cctype.h:165
ystdex::isprint_ASCII
bool isprint_ASCII(char c)
使用 US-ASCII 字符集的 std::isprint 。
Definition: cctype.h:96
platform_ex::Windows::unsigned
YF_API unsigned
Definition: NLS.h:52
ystdex::toupper
char toupper(char c)
Definition: cctype.h:172
ystdex::isdigit
bool isdigit(char c)
区域无关的 std::isdigit 。
Definition: cctype.h:129
ystdex::isprint_ISO8859_1
bool isprint_ISO8859_1(char c)
使用 ISO/IEC 8859-1 字符集的 std::isprint 。
Definition: cctype.h:103
YB_STATELESS
#define YB_STATELESS
指示函数或函数模板实例为无状态函数。
Definition: ydef.h:941
ystdex::iscntrl_ASCII
bool iscntrl_ASCII(char c)
使用 US-ASCII 字符集的 std::isprint 。
Definition: cctype.h:70
ystdex::isspace
bool isspace(char c)
区域无关的 std::isspace 。
Definition: cctype.h:140
ystdex::tolower
char tolower(char c)
转换大小写字符。
Definition: cctype.h:153
ystdex::iscntrl_ISO8859_1
bool iscntrl_ISO8859_1(char c)
使用 ISO/IEC 8859-1 字符集的 std::iscntrl 。
Definition: cctype.h:85
ystdex::towupper
_tChar towupper(_tChar c)
Definition: cctype.h:184
ystdex::iscntrl_ISO8859_11
bool iscntrl_ISO8859_11(char c)
使用 ISO/IEC 8859-11(Latin/Thai) 字符集的 std::iscntrl 。
Definition: cctype.h:77
ystdex
<memory> 特性测试宏。
Definition: ydef.h:1262
yimpl
#define yimpl(...)
实现标签。
Definition: ydef.h:413
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:1199
yconstfn
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:1073
ystdex::iscntrl_C1
bool iscntrl_C1(char c)
判断指定字符是否为 ISO/IEC 2022 定义的 C1 控制字符。
Definition: cctype.h:60
ystdex::iscntrl_C0
bool iscntrl_C0(char c)
判断指定字符是否为 ISO/IEC 2022 定义的 C0 控制字符。
Definition: cctype.h:49