Leaked source code of windows server 2003
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.

141 lines
3.8 KiB

  1. /***
  2. *mbclevel.c - Tests if char is hiragana, katakana, alphabet or digit.
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Tests for the various industry defined levels of Microsoft Kanji
  8. * Code.
  9. *
  10. *Revision History:
  11. * 11-19-92 KRS Ported from 16-bit sources.
  12. * 09-24-93 CFW Removed #ifdef _KANJI
  13. * 09-29-93 CFW Return false if not Kanji code page.
  14. * 10-05-93 GJF Replace _CRTAPI1 with __cdecl.
  15. * 07-26-94 CFW Bug fix #14685, add 0xEA9F-0xEAA4 to JIS-Kanji level 2.
  16. * 04-24-98 GJF Implemented multithread support based on threadmbcinfo
  17. * structs
  18. *
  19. *******************************************************************************/
  20. #ifdef _MBCS
  21. #include <cruntime.h>
  22. #include <mbdata.h>
  23. #include <mbstring.h>
  24. #include <mbctype.h>
  25. #include <mtdll.h>
  26. /***
  27. *int _ismbcl0(c) - Tests if char is hiragana, katakana, alphabet or digit.
  28. *
  29. *Purpose:
  30. * Tests if a given char is hiragana, katakana, alphabet, digit or symbol
  31. * of Microsoft Kanji code.
  32. *
  33. *Entry:
  34. * unsigned int c - Character to test.
  35. *
  36. *Exit:
  37. * Returns non-zero if 0x8140 <= c <= 0x889E, else 0.
  38. *
  39. *Exceptions:
  40. *
  41. *******************************************************************************/
  42. int __cdecl _ismbcl0(
  43. unsigned int c
  44. )
  45. {
  46. #ifdef _MT
  47. pthreadmbcinfo ptmbci = _getptd()->ptmbcinfo;
  48. if ( ptmbci != __ptmbcinfo )
  49. ptmbci = __updatetmbcinfo();
  50. return( (ptmbci->mbcodepage == _KANJI_CP) &&
  51. (__ismbblead_mt(ptmbci, c >> 8)) &&
  52. (__ismbbtrail_mt(ptmbci, c & 0x0ff)) &&
  53. (c < 0x889f) );
  54. #else
  55. return( (__mbcodepage == _KANJI_CP) && (_ismbblead(c >> 8)) &&
  56. (_ismbbtrail(c & 0x0ff)) && (c < 0x889f) );
  57. #endif
  58. }
  59. /***
  60. *int _ismbcl1(c) - Tests for 1st-level Microsoft Kanji code set.
  61. *
  62. *Purpose:
  63. * Tests if a given char belongs to Microsoft 1st-level Kanji code set.
  64. *
  65. *Entry:
  66. * unsigned int c - character to test.
  67. *
  68. *Exit:
  69. * Returns non-zero if 1st-level, else 0.
  70. *
  71. *Exceptions:
  72. *
  73. *******************************************************************************/
  74. int __cdecl _ismbcl1(
  75. unsigned int c
  76. )
  77. {
  78. #ifdef _MT
  79. pthreadmbcinfo ptmbci = _getptd()->ptmbcinfo;
  80. if ( ptmbci != __ptmbcinfo )
  81. ptmbci = __updatetmbcinfo();
  82. return( (ptmbci->mbcodepage == _KANJI_CP) &&
  83. (__ismbblead_mt(ptmbci, c >> 8)) &&
  84. (__ismbbtrail_mt(ptmbci, c & 0x0ff)) &&
  85. (c >= 0x889f) && (c <= 0x9872) );
  86. #else
  87. return( (__mbcodepage == _KANJI_CP) && (_ismbblead(c >> 8)) &&
  88. (_ismbbtrail(c & 0x0ff)) && (c >= 0x889f) && (c <= 0x9872) );
  89. #endif
  90. }
  91. /***
  92. *int _ismbcl2(c) - Tests for a 2nd-level Microsoft Kanji code character.
  93. *
  94. *Purpose:
  95. * Tests if a given char belongs to the Microsoft 2nd-level Kanji code set.
  96. *
  97. *Entry:
  98. * unsigned int c - character to test.
  99. *
  100. *Exit:
  101. * Returns non-zero if 2nd-level, else 0.
  102. *
  103. *Exceptions:
  104. *
  105. *******************************************************************************/
  106. int __cdecl _ismbcl2(
  107. unsigned int c
  108. )
  109. {
  110. #ifdef _MT
  111. pthreadmbcinfo ptmbci = _getptd()->ptmbcinfo;
  112. if ( ptmbci != __ptmbcinfo )
  113. ptmbci = __updatetmbcinfo();
  114. return( (ptmbci->mbcodepage == _KANJI_CP) &&
  115. (__ismbblead_mt(ptmbci, c >> 8)) &&
  116. (__ismbbtrail_mt(ptmbci, c & 0x0ff)) &&
  117. (c >= 0x989f) && (c <= 0xEAA4) );
  118. #else
  119. return( (__mbcodepage == _KANJI_CP) && (_ismbblead(c >> 8)) &&
  120. (_ismbbtrail(c & 0x0ff)) && (c >= 0x989f) && (c <= 0xEAA4) );
  121. #endif
  122. }
  123. #endif /* _MBCS */