ReactOS 0.4.16-dev-852-gcfcc8d8
_ctype.cpp
Go to the documentation of this file.
1//
2// _ctype.cpp
3//
4// Copyright (c) Microsoft Corporation. All rights reserved.
5//
6// Defines the function equivalents of the character classification macros in
7// <ctype.h>. These function definitions make use of the macros. The functions
8// return zero if the character does not meet the requirements, and nonzero if
9// the character does meet the requirements.
10//
11#include <corecrt_internal.h>
12#include <ctype.h>
13#include <locale.h>
14
15// The ctype functions (isalnum(), isupper(), etc) are very small and quick.
16// Optimizing for size has a measurable negative impact, so we optimize for speed here.
17#pragma optimize("t", on)
18
19static __forceinline int fast_check_initial_locale(int const c, int const mask) throw()
20{
21 #ifdef _DEBUG
22 return _chvalidator(c, mask);
23 #else
25 #endif
26}
27
28static __forceinline int fast_check_current_locale(int const c, int const mask) throw()
29{
30 // Avoid PTD lookup when locale is unchanged.
31 if (!__acrt_locale_changed())
32 {
34 }
35
36 // Avoid _LocaleUpdate overhead:
37 // * Extra un-inlined function calls
38 // * Multibyte locale synchronization
39 // * Marking/unmarking current thread as using per-thread-locales.
40
41 __acrt_ptd * const ptd{__acrt_getptd()};
42 __crt_locale_data * locale_info{ptd->_locale_info};
43 __acrt_update_locale_info(ptd, &locale_info);
44
45 // Common case
46 if (c >= -1 && c <= 255)
47 {
48 return locale_info->_public._locale_pctype[c] & mask;
49 }
50
51 // Microsoft Extension: Translate int values outside of unsigned char range for DBCS locales
52 // Note that our documentation also clearly states this is undefined.
53 if (locale_info->_public._locale_mb_cur_max > 1)
54 {
55 return _isctype_l(c, mask, nullptr);
56 }
57
58 return 0;
59}
60
61static __forceinline int fast_check_given_locale(int const c, int const mask, _locale_t const locale) throw()
62{
63 // Avoid _LocaleUpdate overhead - just check whether it's nullptr.
64 if (locale == nullptr) {
66 }
67
68 // Common case
69 if (c >= -1 && c <= 255)
70 {
71 return locale->locinfo->_public._locale_pctype[c] & mask;
72 }
73
74 // Microsoft Extension: Translate int values outside of unsigned char range for DBCS locales
75 // Note that our documentation also clearly states this is undefined.
76 if (locale->locinfo->_public._locale_mb_cur_max > 1)
77 {
78 return _isctype_l(c, mask, locale);
79 }
80
81 return 0;
82}
83
84
85extern "C" int (__cdecl _isalpha_l)(int const c, _locale_t const locale)
86{
88}
89
90extern "C" int (__cdecl isalpha)(int const c)
91{
93}
94
95
96extern "C" int (__cdecl _isupper_l)(int const c, _locale_t const locale)
97{
99}
100
101extern "C" int (__cdecl isupper)(int const c)
102{
104}
105
106
107extern "C" int (__cdecl _islower_l)(int const c, _locale_t const locale)
108{
110}
111
112extern "C" int (__cdecl islower)(int const c)
113{
115}
116
117
118extern "C" int (__cdecl _isdigit_l)(int const c, _locale_t const locale)
119{
121}
122
123extern "C" int (__cdecl isdigit)(int const c)
124{
126}
127
128
129extern "C" int (__cdecl _isxdigit_l)(int const c, _locale_t const locale)
130{
132}
133
134extern "C" int (__cdecl isxdigit)(int const c)
135{
137}
138
139
140extern "C" int (__cdecl _isspace_l)(int const c, _locale_t const locale)
141{
143}
144
145extern "C" int (__cdecl isspace)(int const c)
146{
148}
149
150
151extern "C" int (__cdecl _ispunct_l)(int const c, _locale_t const locale)
152{
154}
155
156extern "C" int (__cdecl ispunct)(int const c)
157{
159}
160
161
162extern "C" int (__cdecl _isblank_l)(int const c, _locale_t const locale)
163{
165}
166
167extern "C" int (__cdecl isblank)(int const c)
168{
169 // \t is a blank character, but is not registered as _Blank on the table, because that will make it
170 //printable. Also Windows (via GetStringType()) considered all _BLANK characters to also be _PRINT characters,
171 //so does not have a way to specify blank, non-printable.
172 if (c == '\t') {
173 return _BLANK;
174 }
175
177}
178
179
180extern "C" int (__cdecl _isalnum_l)(int const c, _locale_t const locale)
181{
183}
184
185extern "C" int (__cdecl isalnum)(int const c)
186{
188}
189
190
191extern "C" int (__cdecl _isprint_l)(int const c, _locale_t const locale)
192{
194}
195
196extern "C" int (__cdecl isprint)(int const c)
197{
199}
200
201
202extern "C" int (__cdecl _isgraph_l)(int const c, _locale_t const locale)
203{
205}
206
207extern "C" int (__cdecl isgraph)(int const c)
208{
210}
211
212
213extern "C" int (__cdecl _iscntrl_l)(int const c, _locale_t const locale)
214{
216}
217
218extern "C" int (__cdecl iscntrl)(int const c)
219{
221}
222
223
224extern "C" int (__cdecl __isascii)(int const c)
225{
226 return __isascii(c);
227}
228
229extern "C" int (__cdecl __toascii)(int const c)
230{
231 return __toascii(c);
232}
233
234
235extern "C" int (__cdecl _iscsymf_l)(int const c, _locale_t const locale)
236{
237 return (_isalpha_l)(c, locale) || c == '_';
238}
239
240extern "C" int (__cdecl __iscsymf)(int const c)
241{
242 return __iscsymf(c);
243}
244
245
246extern "C" int (__cdecl _iscsym_l)(int const c, _locale_t const locale)
247{
248 return (_isalnum_l)(c, locale) || c == '_';
249}
250
251extern "C" int (__cdecl __iscsym)(int const c)
252{
253 return __iscsym(static_cast<unsigned char>(c));
254}
_locale_t const locale
Definition: _ctype.cpp:86
static __forceinline int fast_check_initial_locale(int const c, int const mask)
Definition: _ctype.cpp:19
static __forceinline int fast_check_given_locale(int const c, int const mask, _locale_t const locale)
Definition: _ctype.cpp:61
static __forceinline int fast_check_current_locale(int const c, int const mask)
Definition: _ctype.cpp:28
#define isspace(c)
Definition: acclib.h:69
#define islower(c)
Definition: acclib.h:72
#define isalpha(c)
Definition: acclib.h:74
#define isdigit(c)
Definition: acclib.h:68
#define isprint(c)
Definition: acclib.h:73
#define isxdigit(c)
Definition: acclib.h:70
#define isupper(c)
Definition: acclib.h:71
#define __cdecl
Definition: accygwin.h:79
Definition: _locale.h:75
__acrt_ptd *__cdecl __acrt_getptd(void)
__crt_locale_data __acrt_initial_locale_data
Definition: nlsdata.cpp:92
_In_ size_t const _In_ int _In_ bool const _In_ unsigned const _In_ __acrt_rounding_mode const _Inout_ __crt_cached_ptd_host & ptd
Definition: cvt.cpp:355
static int __CRTDECL __acrt_locale_get_ctype_array_value(_In_reads_(_Char_value+1) unsigned short const *const locale_pctype_array, _In_range_(-1, 255) int const c, _In_ int const mask)
Definition: stubs.c:113
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
const GLubyte * c
Definition: glext.h:8905
GLenum GLint GLuint mask
Definition: glext.h:6028
#define __iscsym(_c)
Definition: ctype.h:691
#define _iscsymf_l(_c, _p)
Definition: ctype.h:694
#define _islower_l(_Char, _Locale)
Definition: ctype.h:645
#define _BLANK
Definition: ctype.h:72
#define _isspace_l(_Char, _Locale)
Definition: ctype.h:648
#define _PUNCT
Definition: ctype.h:70
#define _CONTROL
Definition: ctype.h:71
#define _LOWER
Definition: ctype.h:66
_Check_return_ _CRTIMP int __cdecl _isctype_l(_In_ int _C, _In_ int _Type, _In_opt_ _locale_t _Locale)
#define _SPACE
Definition: ctype.h:68
#define _ALPHA
Definition: ctype.h:76
#define __isascii(_Char)
Definition: ctype.h:656
#define _isprint_l(_Char, _Locale)
Definition: ctype.h:651
_Check_return_ _CRTIMP int __cdecl ispunct(_In_ int _C)
#define _isalnum_l(_Char, _Locale)
Definition: ctype.h:650
#define __toascii(_Char)
Definition: ctype.h:657
#define _UPPER
Definition: ctype.h:65
#define _isalpha_l(_Char, _Locale)
Definition: ctype.h:643
_Check_return_ _CRTIMP int __cdecl isgraph(_In_ int _C)
#define _isdigit_l(_Char, _Locale)
Definition: ctype.h:646
#define _ispunct_l(_Char, _Locale)
Definition: ctype.h:649
#define _HEX
Definition: ctype.h:73
_Check_return_ _CRTIMP int __cdecl iscntrl(_In_ int _C)
#define _iscsym_l(_c, _p)
Definition: ctype.h:695
#define _DIGIT
Definition: ctype.h:67
#define _iscntrl_l(_Char, _Locale)
Definition: ctype.h:653
#define _isgraph_l(_Char, _Locale)
Definition: ctype.h:652
#define __iscsymf(_c)
Definition: ctype.h:690
#define _isupper_l(_Char, _Locale)
Definition: ctype.h:644
#define _isxdigit_l(_Char, _Locale)
Definition: ctype.h:647
_Check_return_ _CRTIMP int __cdecl isalnum(_In_ int _C)
#define _isblank_l(c, locale)
Definition: ctype.h:270
#define c
Definition: ke_i.h:80
void __acrt_update_locale_info(__acrt_ptd *const ptd, __crt_locale_data **const locale_info)
unsigned short const * _locale_pctype
Definition: stubs.c:95
__crt_locale_data_public _public
#define isblank(x)
Definition: trio.c:93