xref: /reactos/sdk/lib/ucrt/mbstring/ismbbyte.cpp (revision 04e0dc4a)
1*04e0dc4aSTimo Kreuzer /***
2*04e0dc4aSTimo Kreuzer *ismbbyte.c - Function versions of MBCS ctype macros
3*04e0dc4aSTimo Kreuzer *
4*04e0dc4aSTimo Kreuzer *       Copyright (c) Microsoft Corporation.  All rights reserved.
5*04e0dc4aSTimo Kreuzer *
6*04e0dc4aSTimo Kreuzer *Purpose:
7*04e0dc4aSTimo Kreuzer *       This files provides function versions of the character
8*04e0dc4aSTimo Kreuzer *       classification a*d conversion macros in mbctype.h.
9*04e0dc4aSTimo Kreuzer *
10*04e0dc4aSTimo Kreuzer *******************************************************************************/
11*04e0dc4aSTimo Kreuzer #ifndef _MBCS
12*04e0dc4aSTimo Kreuzer     #error This file should only be compiled with _MBCS defined
13*04e0dc4aSTimo Kreuzer #endif
14*04e0dc4aSTimo Kreuzer 
15*04e0dc4aSTimo Kreuzer #include <corecrt_internal_mbstring.h>
16*04e0dc4aSTimo Kreuzer #include <locale.h>
17*04e0dc4aSTimo Kreuzer 
18*04e0dc4aSTimo Kreuzer /* defined in mbctype.h
19*04e0dc4aSTimo Kreuzer ; Define masks
20*04e0dc4aSTimo Kreuzer 
21*04e0dc4aSTimo Kreuzer ; set bit masks for the possible kanji character types
22*04e0dc4aSTimo Kreuzer ; (all MBCS bit masks start with "_M")
23*04e0dc4aSTimo Kreuzer 
24*04e0dc4aSTimo Kreuzer _MS             equ     01h     ; MBCS non-ascii single byte char
25*04e0dc4aSTimo Kreuzer _MP             equ     02h     ; MBCS punct
26*04e0dc4aSTimo Kreuzer _M1             equ     04h     ; MBCS 1st (lead) byte
27*04e0dc4aSTimo Kreuzer _M2             equ     08h     ; MBCS 2nd byte
28*04e0dc4aSTimo Kreuzer 
29*04e0dc4aSTimo Kreuzer */
30*04e0dc4aSTimo Kreuzer 
31*04e0dc4aSTimo Kreuzer /* defined in ctype.h
32*04e0dc4aSTimo Kreuzer ; set bit masks for the possible character types
33*04e0dc4aSTimo Kreuzer 
34*04e0dc4aSTimo Kreuzer _UPPER          equ     01h     ; upper case letter
35*04e0dc4aSTimo Kreuzer _LOWER          equ     02h     ; lower case letter
36*04e0dc4aSTimo Kreuzer _DIGIT          equ     04h     ; digit[0-9]
37*04e0dc4aSTimo Kreuzer _SPACE          equ     08h     ; tab, carriage return, newline,
38*04e0dc4aSTimo Kreuzer                                 ; vertical tab or form feed
39*04e0dc4aSTimo Kreuzer _PUNCT          equ     10h     ; punctuation character
40*04e0dc4aSTimo Kreuzer _CONTROL        equ     20h     ; control character
41*04e0dc4aSTimo Kreuzer _BLANK          equ     40h     ; space char
42*04e0dc4aSTimo Kreuzer _HEX            equ     80h     ; hexadecimal digit
43*04e0dc4aSTimo Kreuzer 
44*04e0dc4aSTimo Kreuzer */
45*04e0dc4aSTimo Kreuzer 
46*04e0dc4aSTimo Kreuzer /* defined in ctype.h, mbdata.h
47*04e0dc4aSTimo Kreuzer         extrn   __mbctype:byte          ; MBCS ctype table
48*04e0dc4aSTimo Kreuzer         extrn   __ctype_:byte           ; ANSI/ASCII ctype table
49*04e0dc4aSTimo Kreuzer */
50*04e0dc4aSTimo Kreuzer 
51*04e0dc4aSTimo Kreuzer 
52*04e0dc4aSTimo Kreuzer /***
53*04e0dc4aSTimo Kreuzer * ismbbyte - Function versions of mbctype macros
54*04e0dc4aSTimo Kreuzer *
55*04e0dc4aSTimo Kreuzer *Purpose:
56*04e0dc4aSTimo Kreuzer *
57*04e0dc4aSTimo Kreuzer *Entry:
58*04e0dc4aSTimo Kreuzer *       int = character to be tested
59*04e0dc4aSTimo Kreuzer *Exit:
60*04e0dc4aSTimo Kreuzer *       ax = non-zero = character is of the requested type
61*04e0dc4aSTimo Kreuzer *          =        0 = character is NOT of the requested type
62*04e0dc4aSTimo Kreuzer *
63*04e0dc4aSTimo Kreuzer *Uses:
64*04e0dc4aSTimo Kreuzer *
65*04e0dc4aSTimo Kreuzer *Exceptions:
66*04e0dc4aSTimo Kreuzer *
67*04e0dc4aSTimo Kreuzer *******************************************************************************/
68*04e0dc4aSTimo Kreuzer 
69*04e0dc4aSTimo Kreuzer static int __cdecl x_ismbbtype_l(_locale_t plocinfo, unsigned int, int, int) throw();
70*04e0dc4aSTimo Kreuzer 
71*04e0dc4aSTimo Kreuzer 
72*04e0dc4aSTimo Kreuzer /* ismbbk functions */
73*04e0dc4aSTimo Kreuzer 
74*04e0dc4aSTimo Kreuzer extern "C" int (__cdecl _ismbbkalnum_l) (unsigned int tst, _locale_t plocinfo)
75*04e0dc4aSTimo Kreuzer {
76*04e0dc4aSTimo Kreuzer     return x_ismbbtype_l(plocinfo,tst,0,_MS);
77*04e0dc4aSTimo Kreuzer }
78*04e0dc4aSTimo Kreuzer 
79*04e0dc4aSTimo Kreuzer extern "C" int (__cdecl _ismbbkalnum) (unsigned int tst)
80*04e0dc4aSTimo Kreuzer {
81*04e0dc4aSTimo Kreuzer     return x_ismbbtype_l(nullptr,tst,0,_MS);
82*04e0dc4aSTimo Kreuzer }
83*04e0dc4aSTimo Kreuzer 
84*04e0dc4aSTimo Kreuzer extern "C" int (__cdecl _ismbbkprint_l) (unsigned int tst, _locale_t plocinfo)
85*04e0dc4aSTimo Kreuzer {
86*04e0dc4aSTimo Kreuzer     return x_ismbbtype_l(plocinfo,tst,0,(_MS | _MP));
87*04e0dc4aSTimo Kreuzer }
88*04e0dc4aSTimo Kreuzer 
89*04e0dc4aSTimo Kreuzer extern "C" int (__cdecl _ismbbkprint) (unsigned int tst)
90*04e0dc4aSTimo Kreuzer {
91*04e0dc4aSTimo Kreuzer     return x_ismbbtype_l(nullptr,tst,0,(_MS | _MP));
92*04e0dc4aSTimo Kreuzer }
93*04e0dc4aSTimo Kreuzer 
94*04e0dc4aSTimo Kreuzer extern "C" int (__cdecl _ismbbkpunct_l) (unsigned int tst, _locale_t plocinfo)
95*04e0dc4aSTimo Kreuzer {
96*04e0dc4aSTimo Kreuzer     return x_ismbbtype_l(plocinfo,tst,0,_MP);
97*04e0dc4aSTimo Kreuzer }
98*04e0dc4aSTimo Kreuzer 
99*04e0dc4aSTimo Kreuzer extern "C" int (__cdecl _ismbbkpunct) (unsigned int tst)
100*04e0dc4aSTimo Kreuzer {
101*04e0dc4aSTimo Kreuzer     return x_ismbbtype_l(nullptr,tst,0,_MP);
102*04e0dc4aSTimo Kreuzer }
103*04e0dc4aSTimo Kreuzer 
104*04e0dc4aSTimo Kreuzer 
105*04e0dc4aSTimo Kreuzer /* ismbb functions */
106*04e0dc4aSTimo Kreuzer 
107*04e0dc4aSTimo Kreuzer extern "C" int (__cdecl _ismbbalnum_l) (unsigned int tst, _locale_t plocinfo)
108*04e0dc4aSTimo Kreuzer {
109*04e0dc4aSTimo Kreuzer     return x_ismbbtype_l(plocinfo,tst,(_ALPHA | _DIGIT), _MS);
110*04e0dc4aSTimo Kreuzer }
111*04e0dc4aSTimo Kreuzer 
112*04e0dc4aSTimo Kreuzer extern "C" int (__cdecl _ismbbalnum) (unsigned int tst)
113*04e0dc4aSTimo Kreuzer {
114*04e0dc4aSTimo Kreuzer     return x_ismbbtype_l(nullptr,tst,(_ALPHA | _DIGIT), _MS);
115*04e0dc4aSTimo Kreuzer }
116*04e0dc4aSTimo Kreuzer 
117*04e0dc4aSTimo Kreuzer extern "C" int (__cdecl _ismbbalpha_l) (unsigned int tst, _locale_t plocinfo)
118*04e0dc4aSTimo Kreuzer {
119*04e0dc4aSTimo Kreuzer     return x_ismbbtype_l(plocinfo,tst,_ALPHA, _MS);
120*04e0dc4aSTimo Kreuzer }
121*04e0dc4aSTimo Kreuzer 
122*04e0dc4aSTimo Kreuzer extern "C" int (__cdecl _ismbbalpha) (unsigned int tst)
123*04e0dc4aSTimo Kreuzer {
124*04e0dc4aSTimo Kreuzer     return x_ismbbtype_l(nullptr,tst,_ALPHA, _MS);
125*04e0dc4aSTimo Kreuzer }
126*04e0dc4aSTimo Kreuzer 
127*04e0dc4aSTimo Kreuzer extern "C" int (__cdecl _ismbbgraph_l) (unsigned int tst, _locale_t plocinfo)
128*04e0dc4aSTimo Kreuzer {
129*04e0dc4aSTimo Kreuzer     return x_ismbbtype_l(plocinfo,tst,(_PUNCT | _ALPHA | _DIGIT),(_MS | _MP));
130*04e0dc4aSTimo Kreuzer }
131*04e0dc4aSTimo Kreuzer 
132*04e0dc4aSTimo Kreuzer extern "C" int (__cdecl _ismbbgraph) (unsigned int tst)
133*04e0dc4aSTimo Kreuzer {
134*04e0dc4aSTimo Kreuzer     return x_ismbbtype_l(nullptr,tst,(_PUNCT | _ALPHA | _DIGIT),(_MS | _MP));
135*04e0dc4aSTimo Kreuzer }
136*04e0dc4aSTimo Kreuzer 
137*04e0dc4aSTimo Kreuzer extern "C" int (__cdecl _ismbbprint_l) (unsigned int tst, _locale_t plocinfo)
138*04e0dc4aSTimo Kreuzer {
139*04e0dc4aSTimo Kreuzer     return x_ismbbtype_l(plocinfo,tst,(_BLANK | _PUNCT | _ALPHA | _DIGIT),(_MS | _MP));
140*04e0dc4aSTimo Kreuzer }
141*04e0dc4aSTimo Kreuzer 
142*04e0dc4aSTimo Kreuzer extern "C" int (__cdecl _ismbbprint) (unsigned int tst)
143*04e0dc4aSTimo Kreuzer {
144*04e0dc4aSTimo Kreuzer     return x_ismbbtype_l(nullptr,tst,(_BLANK | _PUNCT | _ALPHA | _DIGIT),(_MS | _MP));
145*04e0dc4aSTimo Kreuzer }
146*04e0dc4aSTimo Kreuzer 
147*04e0dc4aSTimo Kreuzer extern "C" int (__cdecl _ismbbpunct_l) (unsigned int tst, _locale_t plocinfo)
148*04e0dc4aSTimo Kreuzer {
149*04e0dc4aSTimo Kreuzer     return x_ismbbtype_l(plocinfo,tst,_PUNCT, _MP);
150*04e0dc4aSTimo Kreuzer }
151*04e0dc4aSTimo Kreuzer 
152*04e0dc4aSTimo Kreuzer extern "C" int (__cdecl _ismbbpunct) (unsigned int tst)
153*04e0dc4aSTimo Kreuzer {
154*04e0dc4aSTimo Kreuzer     return x_ismbbtype_l(nullptr,tst,_PUNCT, _MP);
155*04e0dc4aSTimo Kreuzer }
156*04e0dc4aSTimo Kreuzer 
157*04e0dc4aSTimo Kreuzer extern "C" int (__cdecl _ismbbblank_l) (unsigned int tst, _locale_t plocinfo)
158*04e0dc4aSTimo Kreuzer {
159*04e0dc4aSTimo Kreuzer     return (tst == '\t') ? _BLANK : x_ismbbtype_l(plocinfo,tst,_BLANK, _MP);
160*04e0dc4aSTimo Kreuzer }
161*04e0dc4aSTimo Kreuzer 
162*04e0dc4aSTimo Kreuzer extern "C" int (__cdecl _ismbbblank) (unsigned int tst)
163*04e0dc4aSTimo Kreuzer {
164*04e0dc4aSTimo Kreuzer     return (tst == '\t') ? _BLANK : x_ismbbtype_l(nullptr,tst,_BLANK, _MP);
165*04e0dc4aSTimo Kreuzer }
166*04e0dc4aSTimo Kreuzer 
167*04e0dc4aSTimo Kreuzer 
168*04e0dc4aSTimo Kreuzer /* lead and trail */
169*04e0dc4aSTimo Kreuzer // These expect single or double byte codepages and are undefined for UTF-8
170*04e0dc4aSTimo Kreuzer // UTF-8 queries will always return false for lead/trail bytes.
171*04e0dc4aSTimo Kreuzer extern "C" int (__cdecl _ismbblead_l) (unsigned int tst, _locale_t plocinfo)
172*04e0dc4aSTimo Kreuzer {
173*04e0dc4aSTimo Kreuzer     // Note: Lookup is always FALSE for UTF-8
174*04e0dc4aSTimo Kreuzer     return x_ismbbtype_l(plocinfo,tst,0,_M1);
175*04e0dc4aSTimo Kreuzer }
176*04e0dc4aSTimo Kreuzer 
177*04e0dc4aSTimo Kreuzer extern "C" int (__cdecl _ismbblead) (unsigned int tst)
178*04e0dc4aSTimo Kreuzer {
179*04e0dc4aSTimo Kreuzer     // Note: Lookup is always FALSE for UTF-8
180*04e0dc4aSTimo Kreuzer     return x_ismbbtype_l(nullptr, tst, 0, _M1);
181*04e0dc4aSTimo Kreuzer }
182*04e0dc4aSTimo Kreuzer 
183*04e0dc4aSTimo Kreuzer extern "C" int (__cdecl _ismbbtrail_l) (unsigned int tst, _locale_t plocinfo)
184*04e0dc4aSTimo Kreuzer {
185*04e0dc4aSTimo Kreuzer     // Note: Lookup is always FALSE for UTF-8
186*04e0dc4aSTimo Kreuzer     return x_ismbbtype_l(plocinfo,tst,0,_M2);
187*04e0dc4aSTimo Kreuzer }
188*04e0dc4aSTimo Kreuzer 
189*04e0dc4aSTimo Kreuzer extern "C" int (__cdecl _ismbbtrail) (unsigned int tst)
190*04e0dc4aSTimo Kreuzer {
191*04e0dc4aSTimo Kreuzer     // Note: Lookup is always FALSE for UTF-8
192*04e0dc4aSTimo Kreuzer     return x_ismbbtype_l(nullptr, tst, 0, _M2);
193*04e0dc4aSTimo Kreuzer }
194*04e0dc4aSTimo Kreuzer 
195*04e0dc4aSTimo Kreuzer 
196*04e0dc4aSTimo Kreuzer /* 932 specific */
197*04e0dc4aSTimo Kreuzer 
198*04e0dc4aSTimo Kreuzer extern "C" int (__cdecl _ismbbkana_l) (unsigned int tst, _locale_t plocinfo)
199*04e0dc4aSTimo Kreuzer {
200*04e0dc4aSTimo Kreuzer     _LocaleUpdate _loc_update(plocinfo);
201*04e0dc4aSTimo Kreuzer     if(_loc_update.GetLocaleT()->mbcinfo &&
202*04e0dc4aSTimo Kreuzer        _loc_update.GetLocaleT()->mbcinfo->mbcodepage == _KANJI_CP)
203*04e0dc4aSTimo Kreuzer     {
204*04e0dc4aSTimo Kreuzer         return x_ismbbtype_l(plocinfo,tst,0,(_MS | _MP));
205*04e0dc4aSTimo Kreuzer     }
206*04e0dc4aSTimo Kreuzer     return FALSE;
207*04e0dc4aSTimo Kreuzer }
208*04e0dc4aSTimo Kreuzer 
209*04e0dc4aSTimo Kreuzer extern "C" int (__cdecl _ismbbkana) (unsigned int tst)
210*04e0dc4aSTimo Kreuzer {
211*04e0dc4aSTimo Kreuzer     return _ismbbkana_l(tst, nullptr);
212*04e0dc4aSTimo Kreuzer }
213*04e0dc4aSTimo Kreuzer 
214*04e0dc4aSTimo Kreuzer /***
215*04e0dc4aSTimo Kreuzer * Common code
216*04e0dc4aSTimo Kreuzer *
217*04e0dc4aSTimo Kreuzer *      cmask = mask for _ctype[] table
218*04e0dc4aSTimo Kreuzer *      kmask = mask for _mbctype[] table
219*04e0dc4aSTimo Kreuzer *
220*04e0dc4aSTimo Kreuzer *******************************************************************************/
221*04e0dc4aSTimo Kreuzer 
x_ismbbtype_l(_locale_t plocinfo,unsigned int tst,int cmask,int kmask)222*04e0dc4aSTimo Kreuzer static int __cdecl x_ismbbtype_l (_locale_t plocinfo, unsigned int tst, int cmask, int kmask) throw()
223*04e0dc4aSTimo Kreuzer {
224*04e0dc4aSTimo Kreuzer     _LocaleUpdate _loc_update(plocinfo);
225*04e0dc4aSTimo Kreuzer 
226*04e0dc4aSTimo Kreuzer     /*
227*04e0dc4aSTimo Kreuzer      * get input character and make sure < 256
228*04e0dc4aSTimo Kreuzer      */
229*04e0dc4aSTimo Kreuzer     tst = (unsigned int)(unsigned char)tst;
230*04e0dc4aSTimo Kreuzer 
231*04e0dc4aSTimo Kreuzer     return  ((*(_loc_update.GetLocaleT()->mbcinfo->mbctype+1+tst)) & kmask) ||
232*04e0dc4aSTimo Kreuzer             ((cmask) ? ((*(_loc_update.GetLocaleT()->locinfo->_public._locale_pctype + tst)) & cmask) : 0);
233*04e0dc4aSTimo Kreuzer }
234