STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ctype.h
Go to the documentation of this file.
1 //
2 // ctype.h
3 //
4 // Copyright (c) Microsoft Corporation. All rights reserved.
5 //
6 // This file declares the narrow character (char) classification functionality.
7 //
8 #pragma once
9 #define _INC_CTYPE
10 
11 #include <corecrt.h>
12 #include <corecrt_wctype.h>
13 
15 #if !defined __midl && !defined RC_INVOKED
16 
17 
18 
19 //-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
20 //
21 // Character Classification Function Declarations
22 //
23 //-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
24 _Check_return_ _ACRTIMP int __cdecl _isctype(_In_ int _C, _In_ int _Type);
32 
33 _When_(_Param_(1) == 0, _Post_equal_to_(0))
35 
37 _Check_return_ _ACRTIMP int __cdecl isxdigit(_In_ int _C);
38 _Check_return_ _ACRTIMP int __cdecl _isxdigit_l(_In_ int _C, _In_opt_ _locale_t _Locale);
39 
40 _When_(_Param_(1) == 0, _Post_equal_to_(0))
42 
43 _Check_return_ _ACRTIMP int __cdecl _isspace_l(_In_ int _C, _In_opt_ _locale_t _Locale);
44 _Check_return_ _ACRTIMP int __cdecl ispunct(_In_ int _C);
45 _Check_return_ _ACRTIMP int __cdecl _ispunct_l(_In_ int _C, _In_opt_ _locale_t _Locale);
46 _Check_return_ _ACRTIMP int __cdecl isblank(_In_ int _C);
47 _Check_return_ _ACRTIMP int __cdecl _isblank_l(_In_ int _C, _In_opt_ _locale_t _Locale);
49 _Check_return_ _ACRTIMP int __cdecl _isalnum_l(_In_ int _C, _In_opt_ _locale_t _Locale);
50 _Check_return_ _ACRTIMP int __cdecl isprint(_In_ int _C);
51 _Check_return_ _ACRTIMP int __cdecl _isprint_l(_In_ int _C, _In_opt_ _locale_t _Locale);
52 _Check_return_ _ACRTIMP int __cdecl isgraph(_In_ int _C);
53 _Check_return_ _ACRTIMP int __cdecl _isgraph_l(_In_ int _C, _In_opt_ _locale_t _Locale);
54 _Check_return_ _ACRTIMP int __cdecl iscntrl(_In_ int _C);
55 _Check_return_ _ACRTIMP int __cdecl _iscntrl_l(_In_ int _C, _In_opt_ _locale_t _Locale);
56 
57 _When_(_Param_(1) == 0, _Post_equal_to_(0))
59 
60 _When_(_Param_(1) == 0, _Post_equal_to_(0))
62 
64 _Check_return_ _ACRTIMP int __cdecl _tolower_l(_In_ int _C, _In_opt_ _locale_t _Locale);
66 _Check_return_ _ACRTIMP int __cdecl _toupper_l(_In_ int _C, _In_opt_ _locale_t _Locale);
67 
68 _Check_return_ _ACRTIMP int __cdecl __isascii(_In_ int _C);
69 _Check_return_ _ACRTIMP int __cdecl __toascii(_In_ int _C);
70 _Check_return_ _ACRTIMP int __cdecl __iscsymf(_In_ int _C);
71 _Check_return_ _ACRTIMP int __cdecl __iscsym(_In_ int _C);
72 
73 
74 
75 //-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
76 //
77 // Character Classification Macro Definitions
78 //
79 //-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
80 #ifndef _CTYPE_DISABLE_MACROS
81 
82  // Maximum number of bytes in multi-byte character in the current locale
83  // (also defined in stdlib.h).
84  #ifndef MB_CUR_MAX
85  #if defined _CRT_DISABLE_PERFCRIT_LOCKS && !defined _DLL
86  #define MB_CUR_MAX __mb_cur_max
87  #else
88  #define MB_CUR_MAX ___mb_cur_max_func()
89  #endif
90 
91  #ifdef _CRT_DECLARE_GLOBAL_VARIABLES_DIRECTLY
92  extern int __mb_cur_max;
93  #else
94  #define __mb_cur_max (___mb_cur_max_func())
95  #endif
96 
97  // MB_LEN_MAX = 5 in limits.h but we do not include that header here so use 5
98  // directly.
99  _Post_satisfies_(return > 0 && return < 5)
100  _ACRTIMP int __cdecl ___mb_cur_max_func(void);
101  _Post_satisfies_(return > 0 && return < 5)
102  _ACRTIMP int __cdecl ___mb_cur_max_l_func(_locale_t _Locale);
103  #endif
104 
105 
106 
107  // In the debug CRT, we make all calls through the validation function to catch
108  // invalid integer inputs that yield undefined behavior.
109  #ifdef _DEBUG
110  _ACRTIMP int __cdecl _chvalidator(_In_ int _Ch, _In_ int _Mask);
111  #define __chvalidchk(a, b) _chvalidator(a, b)
112  #else
113  #define __chvalidchk(a, b) (__PCTYPE_FUNC[(a)] & (b))
114  #endif
115 
116 
117 
118  #define __ascii_isalpha(c) ( __chvalidchk(c, _ALPHA))
119  #define __ascii_isdigit(c) ( __chvalidchk(c, _DIGIT))
120  #define __ascii_tolower(c) ( (((c) >= 'A') && ((c) <= 'Z')) ? ((c) - 'A' + 'a') : (c) )
121  #define __ascii_toupper(c) ( (((c) >= 'a') && ((c) <= 'z')) ? ((c) - 'a' + 'A') : (c) )
122  #define __ascii_iswalpha(c) ( ('A' <= (c) && (c) <= 'Z') || ( 'a' <= (c) && (c) <= 'z'))
123  #define __ascii_iswdigit(c) ( '0' <= (c) && (c) <= '9')
124  #define __ascii_towlower(c) ( (((c) >= L'A') && ((c) <= L'Z')) ? ((c) - L'A' + L'a') : (c) )
125  #define __ascii_towupper(c) ( (((c) >= L'a') && ((c) <= L'z')) ? ((c) - L'a' + L'A') : (c) )
126 
127 
128 
129  #if defined _CRT_DISABLE_PERFCRIT_LOCKS && !defined _DLL && !defined __cplusplus
130  #define isalpha(c) (MB_CUR_MAX > 1 ? _isctype(c, _ALPHA) : __chvalidchk(c, _ALPHA))
131  #define isupper(c) (MB_CUR_MAX > 1 ? _isctype(c, _UPPER) : __chvalidchk(c, _UPPER))
132  #define islower(c) (MB_CUR_MAX > 1 ? _isctype(c, _LOWER) : __chvalidchk(c, _LOWER))
133  #define isdigit(c) (MB_CUR_MAX > 1 ? _isctype(c, _DIGIT) : __chvalidchk(c, _DIGIT))
134  #define isxdigit(c) (MB_CUR_MAX > 1 ? _isctype(c, _HEX) : __chvalidchk(c, _HEX))
135  #define isspace(c) (MB_CUR_MAX > 1 ? _isctype(c, _SPACE) : __chvalidchk(c, _SPACE))
136  #define ispunct(c) (MB_CUR_MAX > 1 ? _isctype(c, _PUNCT) : __chvalidchk(c, _PUNCT))
137  #define isblank(c) (MB_CUR_MAX > 1 ? (((c) == '\t') ? _BLANK : _isctype(c, _BLANK)) : (((c) == '\t') ? _BLANK : __chvalidchk(c, _BLANK)))
138  #define isalnum(c) (MB_CUR_MAX > 1 ? _isctype(c, _ALPHA | _DIGIT) : __chvalidchk(c, (_ALPHA | _DIGIT)))
139  #define isprint(c) (MB_CUR_MAX > 1 ? _isctype(c, _BLANK | _PUNCT | _ALPHA | _DIGIT) : __chvalidchk(c, (_BLANK | _PUNCT | _ALPHA | _DIGIT)))
140  #define isgraph(c) (MB_CUR_MAX > 1 ? _isctype(c, _PUNCT | _ALPHA | _DIGIT) : __chvalidchk(c, (_PUNCT | _ALPHA | _DIGIT)))
141  #define iscntrl(c) (MB_CUR_MAX > 1 ? _isctype(c, _CONTROL) : __chvalidchk(c, _CONTROL))
142  #endif
143 
144  __inline __crt_locale_data_public* __CRTDECL __acrt_get_locale_data_prefix(void const volatile* const _LocalePointers)
145  {
146  _locale_t const _TypedLocalePointers = (_locale_t)_LocalePointers;
147  return (__crt_locale_data_public*)_TypedLocalePointers->locinfo;
148  }
149 
150  #ifdef _DEBUG
151  _ACRTIMP int __cdecl _chvalidator_l(_In_opt_ _locale_t, _In_ int _Ch, _In_ int _Mask);
152  #endif
153 
154  __inline int __CRTDECL _chvalidchk_l(
155  _In_ int const _C,
156  _In_ int const _Mask,
157  _In_opt_ _locale_t const _Locale
158  )
159  {
160  #ifdef _DEBUG
161  return _chvalidator_l(_Locale, _C, _Mask);
162  #else
163  if (_Locale)
164  {
166  }
167 
168  return __chvalidchk(_C, _Mask);
169  #endif
170  }
171 
172  #define __ascii_isalpha_l(c, locale) (_chvalidchk_l(c, _ALPHA, locale))
173  #define __ascii_isdigit_l(c, locale) (_chvalidchk_l(c, _DIGIT, locale))
174 
175  __inline int __CRTDECL _ischartype_l(
176  _In_ int const _C,
177  _In_ int const _Mask,
178  _In_opt_ _locale_t const _Locale
179  )
180  {
181  if (_Locale && __acrt_get_locale_data_prefix(_Locale)->_locale_mb_cur_max > 1)
182  {
183  return _isctype_l(_C, _Mask, _Locale);
184  }
185 
186  return _chvalidchk_l(_C, _Mask, _Locale);
187  }
188 
189  #define _isalpha_l(c, locale) _ischartype_l(c, _ALPHA, locale)
190  #define _isupper_l(c, locale) _ischartype_l(c, _UPPER, locale)
191  #define _islower_l(c, locale) _ischartype_l(c, _LOWER, locale)
192  #define _isdigit_l(c, locale) _ischartype_l(c, _DIGIT, locale)
193  #define _isxdigit_l(c, locale) _ischartype_l(c, _HEX, locale)
194  #define _isspace_l(c, locale) _ischartype_l(c, _SPACE, locale)
195  #define _ispunct_l(c, locale) _ischartype_l(c, _PUNCT, locale)
196  #define _isblank_l(c, locale) (((c) == '\t') ? _BLANK : _ischartype_l(c, _BLANK, locale))
197  #define _isalnum_l(c, locale) _ischartype_l(c, _ALPHA | _DIGIT, locale)
198  #define _isprint_l(c, locale) _ischartype_l(c, _BLANK | _PUNCT | _ALPHA | _DIGIT, locale)
199  #define _isgraph_l(c, locale) _ischartype_l(c, _PUNCT | _ALPHA | _DIGIT, locale)
200  #define _iscntrl_l(c, locale) _ischartype_l(c, _CONTROL, locale)
201 
202  #define _tolower(c) ((c) - 'A' + 'a')
203  #define _toupper(c) ((c) - 'a' + 'A')
204 
205  #define __isascii(c) ((unsigned)(c) < 0x80)
206  #define __toascii(c) ((c) & 0x7f)
207 
208 
209  // Microsoft C version 2.0 extended ctype macros
210  #define __iscsymf(c) (isalpha(c) || ((c) == '_'))
211  #define __iscsym(c) (isalnum(c) || ((c) == '_'))
212  #define __iswcsymf(c) (iswalpha(c) || ((c) == '_'))
213  #define __iswcsym(c) (iswalnum(c) || ((c) == '_'))
214 
215  #define _iscsymf_l(c, p) (_isalpha_l(c, p) || ((c) == '_'))
216  #define _iscsym_l(c, p) (_isalnum_l(c, p) || ((c) == '_'))
217  #define _iswcsymf_l(c, p) (iswalpha(c) || ((c) == '_'))
218  #define _iswcsym_l(c, p) (iswalnum(c) || ((c) == '_'))
219 
220 #endif // _CTYPE_DISABLE_MACROS
221 
222 
223 #if _CRT_INTERNAL_NONSTDC_NAMES
224  #define isascii __isascii
225  #define toascii __toascii
226  #define iscsymf __iscsymf
227  #define iscsym __iscsym
228 #endif
229 
230 
231 
232 #endif // !defined __midl && !defined RC_INVOKED
return
Definition: corecrt_memcpy_s.h:60
Definition: corecrt.h:489
_Check_return_ _ACRTIMP int __cdecl isgraph(_In_ int _C)
#define _ACRTIMP
Definition: corecrt.h:27
Definition: corecrt.h:482
_Check_return_ _ACRTIMP int __cdecl _tolower_l(_In_ int _C, _In_opt_ _locale_t _Locale)
#define _isblank_l(c, locale)
Definition: ctype.h:196
bool() isspace(_Elem _Ch, const locale &_Loc)
Definition: locale:241
struct __crt_locale_data * locinfo
Definition: corecrt.h:491
#define _toupper(c)
Definition: ctype.h:203
#define __mb_cur_max
Definition: ctype.h:94
#define _isprint_l(c, locale)
Definition: ctype.h:198
#define _CRT_BEGIN_C_HEADER
Definition: vcruntime.h:73
#define _isxdigit_l(c, locale)
Definition: ctype.h:193
_Check_return_ _CRT_JIT_INTRINSIC _ACRTIMP int __cdecl isupper(_In_ int _C)
#define __CRTDECL
Definition: vcruntime.h:156
#define _Check_return_
Definition: sal.h:554
_When_(_Param_(1)==0, _Post_equal_to_(0)) _Check_return_ _CRT_JIT_INTRINSIC _ACRTIMP int __cdecl isdigit(_In_ int _C)
_Check_return_ _In_ wchar_t _Ch
Definition: vcruntime_string.h:89
#define _In_
Definition: sal.h:305
_In_ wctype_t _Type
Definition: corecrt_wctype.h:111
#define _CRT_JIT_INTRINSIC
Definition: corecrt.h:64
#define _In_opt_
Definition: sal.h:306
__inline int __CRTDECL _chvalidchk_l(_In_ int const _C, _In_ int const _Mask, _In_opt_ _locale_t const _Locale)
Definition: ctype.h:154
#define _islower_l(c, locale)
Definition: ctype.h:191
#define __iscsym(c)
Definition: ctype.h:211
__inline __crt_locale_data_public *__CRTDECL __acrt_get_locale_data_prefix(void const volatile *const _LocalePointers)
Definition: ctype.h:144
#define _isspace_l(c, locale)
Definition: ctype.h:194
bool() isdigit(_Elem _Ch, const locale &_Loc)
Definition: locale:211
#define _isdigit_l(c, locale)
Definition: ctype.h:192
_Check_return_ _ACRTIMP int __cdecl iscntrl(_In_ int _C)
#define _Post_equal_to_(expr)
Definition: sal.h:575
unsigned short const * _locale_pctype
Definition: corecrt.h:484
_Post_satisfies_(return > 0 &&return< 5) _ACRTIMP int __cdecl ___mb_cur_max_func(void)
_In_ wchar_t _C
Definition: wchar.h:253
#define _isupper_l(c, locale)
Definition: ctype.h:190
_Check_return_ _ACRTIMP int __cdecl isxdigit(_In_ int _C)
_Check_return_ _CRT_JIT_INTRINSIC _ACRTIMP int __cdecl islower(_In_ int _C)
_Check_return_ _ACRTIMP int __cdecl isprint(_In_ int _C)
#define __chvalidchk(a, b)
Definition: ctype.h:113
#define _iscntrl_l(c, locale)
Definition: ctype.h:200
_Check_return_ _ACRTIMP int __cdecl _isctype_l(_In_ int _C, _In_ int _Type, _In_opt_ _locale_t _Locale)
_Check_return_ _CRT_JIT_INTRINSIC _ACRTIMP int __cdecl isalnum(_In_ int _C)
#define __iscsymf(c)
Definition: ctype.h:210
#define _CRT_END_C_HEADER
Definition: vcruntime.h:76
#define __isascii(c)
Definition: ctype.h:205
#define __toascii(c)
Definition: ctype.h:206
__inline int __CRTDECL _ischartype_l(_In_ int const _C, _In_ int const _Mask, _In_opt_ _locale_t const _Locale)
Definition: ctype.h:175
_Check_return_ _ACRTIMP int __cdecl _toupper_l(_In_ int _C, _In_opt_ _locale_t _Locale)
_Elem() toupper(_Elem _Ch, const locale &_Loc)
Definition: locale:265
_Check_return_opt_ _In_opt_ _locale_t const _Locale
Definition: corecrt_wconio.h:289
_Check_return_ _ACRTIMP int __cdecl ispunct(_In_ int _C)
_CRT_MANAGED_FP_DEPRECATE _In_ unsigned int _Mask
Definition: float.h:235
_CRT_BEGIN_C_HEADER _Check_return_ _ACRTIMP int __cdecl _isctype(_In_ int _C, _In_ int _Type)
_Check_return_ _ACRTIMP int __cdecl isblank(_In_ int _C)
#define _isalnum_l(c, locale)
Definition: ctype.h:197
#define _isalpha_l(c, locale)
Definition: ctype.h:189
_Check_return_ _CRT_JIT_INTRINSIC _ACRTIMP int __cdecl isalpha(_In_ int _C)
_Elem() tolower(_Elem _Ch, const locale &_Loc)
Definition: locale:259
__crt_locale_pointers * _locale_t
Definition: corecrt.h:495
#define _ispunct_l(c, locale)
Definition: ctype.h:195
#define _isgraph_l(c, locale)
Definition: ctype.h:199
#define _tolower(c)
Definition: ctype.h:202