Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

166 lines
3.5 KiB

  1. /***
  2. *ismbbyte.c - Function versions of MBCS ctype macros
  3. *
  4. * Copyright (c) 1988-2001, 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. *Revision History:
  11. * 11-19-92 KRS Ported from 16-bit assembler sources.
  12. * 09-08-93 CFW Remove _KANJI test.
  13. * 09-29-93 CFW Change _ismbbkana, add _ismbbkprint.
  14. * 10-05-93 GJF Replaced _CRTAPI1, _CRTAPI3 with __cdecl.
  15. * 04-08-94 CFW Change to ismbbyte.
  16. * 09-14-94 SKS Add ifstrip directive comment
  17. * 02-11-95 CFW Remove _fastcall.
  18. *
  19. *******************************************************************************/
  20. #ifdef _MBCS
  21. #include <cruntime.h>
  22. #include <ctype.h>
  23. #include <mbdata.h>
  24. #include <mbctype.h>
  25. #include <mbstring.h>
  26. /* defined in mbctype.h
  27. ; Define masks
  28. ; set bit masks for the possible kanji character types
  29. ; (all MBCS bit masks start with "_M")
  30. _MS equ 01h ; MBCS non-ascii single byte char
  31. _MP equ 02h ; MBCS punct
  32. _M1 equ 04h ; MBCS 1st (lead) byte
  33. _M2 equ 08h ; MBCS 2nd byte
  34. */
  35. /* defined in ctype.h
  36. ; set bit masks for the possible character types
  37. _UPPER equ 01h ; upper case letter
  38. _LOWER equ 02h ; lower case letter
  39. _DIGIT equ 04h ; digit[0-9]
  40. _SPACE equ 08h ; tab, carriage return, newline,
  41. ; vertical tab or form feed
  42. _PUNCT equ 10h ; punctuation character
  43. _CONTROL equ 20h ; control character
  44. _BLANK equ 40h ; space char
  45. _HEX equ 80h ; hexadecimal digit
  46. */
  47. /* defined in ctype.h, mbdata.h
  48. extrn __mbctype:byte ; MBCS ctype table
  49. extrn __ctype_:byte ; ANSI/ASCII ctype table
  50. */
  51. /***
  52. * ismbbyte - Function versions of mbctype macros
  53. *
  54. *Purpose:
  55. *
  56. *Entry:
  57. * int = character to be tested
  58. *Exit:
  59. * ax = non-zero = character is of the requested type
  60. * = 0 = character is NOT of the requested type
  61. *
  62. *Uses:
  63. *
  64. *Exceptions:
  65. *
  66. *******************************************************************************/
  67. int __cdecl x_ismbbtype(unsigned int, int, int);
  68. /* ismbbk functions */
  69. int (__cdecl _ismbbkalnum) (unsigned int tst)
  70. {
  71. return x_ismbbtype(tst,0,_MS);
  72. }
  73. int (__cdecl _ismbbkprint) (unsigned int tst)
  74. {
  75. return x_ismbbtype(tst,0,(_MS | _MP));
  76. }
  77. int (__cdecl _ismbbkpunct) (unsigned int tst)
  78. {
  79. return x_ismbbtype(tst,0,_MP);
  80. }
  81. /* ismbb functions */
  82. int (__cdecl _ismbbalnum) (unsigned int tst)
  83. {
  84. return x_ismbbtype(tst,(_ALPHA | _DIGIT), _MS);
  85. }
  86. int (__cdecl _ismbbalpha) (unsigned int tst)
  87. {
  88. return x_ismbbtype(tst,_ALPHA, _MS);
  89. }
  90. int (__cdecl _ismbbgraph) (unsigned int tst)
  91. {
  92. return x_ismbbtype(tst,(_PUNCT | _ALPHA | _DIGIT),(_MS | _MP));
  93. }
  94. int (__cdecl _ismbbprint) (unsigned int tst)
  95. {
  96. return x_ismbbtype(tst,(_BLANK | _PUNCT | _ALPHA | _DIGIT),(_MS | _MP));
  97. }
  98. int (__cdecl _ismbbpunct) (unsigned int tst)
  99. {
  100. return x_ismbbtype(tst,_PUNCT, _MP);
  101. }
  102. /* lead and trail */
  103. int (__cdecl _ismbblead) (unsigned int tst)
  104. {
  105. return x_ismbbtype(tst,0,_M1);
  106. }
  107. int (__cdecl _ismbbtrail) (unsigned int tst)
  108. {
  109. return x_ismbbtype(tst,0,_M2);
  110. }
  111. /* 932 specific */
  112. int (__cdecl _ismbbkana) (unsigned int tst)
  113. {
  114. return (__mbcodepage == _KANJI_CP && x_ismbbtype(tst,0,(_MS | _MP)));
  115. }
  116. /***
  117. * Common code
  118. *
  119. * cmask = mask for _ctype[] table
  120. * kmask = mask for _mbctype[] table
  121. *
  122. *******************************************************************************/
  123. static int __cdecl x_ismbbtype (unsigned int tst, int cmask, int kmask)
  124. {
  125. tst = (unsigned int)(unsigned char)tst; /* get input character
  126. and make sure < 256 */
  127. return ((*(_mbctype+1+tst)) & kmask) ||
  128. ((cmask) ? ((*(_ctype+1+tst)) & cmask) : 0);
  129. }
  130. #endif /* _MBCS */