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