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.

136 lines
3.7 KiB

  1. /***
  2. *ismbalph.c - Test if character is alphabetic (MBCS)
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Test if character is alphabetic (MBCS)
  8. *
  9. *Revision History:
  10. * 11-19-92 KRS Ported from 16-bit sources.
  11. * 09-29-93 CFW Merge _KANJI and _MBCS_OS
  12. * 10-05-93 GJF Replaced _CRTAPI1 with __cdecl.
  13. * 04-12-94 CFW Make function generic.
  14. * 04-18-94 CFW Use _ALPHA rather than _UPPER|_LOWER.
  15. * 04-29-94 CFW Place c in char array.
  16. * 05-19-94 CFW Enable non-Win32.
  17. * 03-16-97 RDK Added error flag to __crtGetStringTypeA.
  18. * 09-11-97 GJF Replaced __mbcodepage == 0 with _ISNOTMBCP.
  19. * 09-26-97 BWT Fix POSIX
  20. * 03-31-98 GJF Implemented multithread support based on threadmbcinfo
  21. * structs
  22. * 10-07-98 GJF MT should have been _MT.
  23. * 05-17-99 PML Remove all Macintosh support.
  24. *
  25. *******************************************************************************/
  26. #ifdef _MBCS
  27. #if !defined(_POSIX_)
  28. #include <windows.h>
  29. #include <awint.h>
  30. #endif /* !_POSIX_ */
  31. #include <mtdll.h>
  32. #include <cruntime.h>
  33. #include <ctype.h>
  34. #include <mbdata.h>
  35. #include <mbctype.h>
  36. #include <mbstring.h>
  37. /***
  38. * _ismbcalpha - Test if character is alphabetic (MBCS)
  39. *
  40. *Purpose:
  41. * Test if character is alphabetic.
  42. * Handles MBCS chars correctly.
  43. *
  44. * Note: Use test against 0x00FF instead of _ISLEADBYTE
  45. * to ensure that we don't call SBCS routine with a two-byte
  46. * value.
  47. *
  48. *Entry:
  49. * unsigned int c = character to test
  50. *
  51. *Exit:
  52. * Returns TRUE if c is alphabetic, else FALSE
  53. *
  54. *Exceptions:
  55. *
  56. *******************************************************************************/
  57. int __cdecl _ismbcalpha(
  58. unsigned int c
  59. )
  60. {
  61. #ifdef _MT
  62. pthreadmbcinfo ptmbci = _getptd()->ptmbcinfo;
  63. if ( ptmbci != __ptmbcinfo )
  64. ptmbci = __updatetmbcinfo();
  65. #endif
  66. if (c > 0x00FF)
  67. {
  68. #if !defined(_POSIX_)
  69. char buf[2];
  70. unsigned short ctype[2] = {0};
  71. buf[0] = (c >> 8) & 0xFF;
  72. buf[1] = c & 0xFF;
  73. /* return FALSE if not in supported MB code page */
  74. #ifdef _MT
  75. if ( _ISNOTMBCP_MT(ptmbci) )
  76. #else
  77. if ( _ISNOTMBCP )
  78. #endif
  79. return 0;
  80. /*
  81. * Since 'c' could be two one-byte MB chars, we need room in the
  82. * ctype return array to handle this. In this case, the
  83. * second word in the return array will be non-zero.
  84. */
  85. if ( __crtGetStringTypeA( CT_CTYPE1,
  86. buf,
  87. 2,
  88. ctype,
  89. #ifdef _MT
  90. ptmbci->mbcodepage,
  91. ptmbci->mblcid,
  92. #else
  93. __mbcodepage,
  94. __mblcid,
  95. #endif
  96. TRUE ) == 0)
  97. return 0;
  98. /* ensure single MB character and test for type */
  99. return (ctype[1] == 0 && ctype[0] & (_ALPHA));
  100. #else /* !_POSIX_ */
  101. return (
  102. ((c >= _MBLOWERLOW1) && (c <= _MBLOWERHIGH1)) ||
  103. ((c >= _MBLOWERLOW2) && (c <= _MBLOWERHIGH2)) ||
  104. ((c >= _MBUPPERLOW1) && (c <= _MBUPPERHIGH1)) ||
  105. ((c >= _MBUPPERLOW2) && (c <= _MBUPPERHIGH2))
  106. );
  107. #endif /* !_POSIX_ */
  108. } else
  109. #ifdef _MT
  110. return __ismbbalpha_mt(ptmbci, c);
  111. #else
  112. return _ismbbalpha(c);
  113. #endif
  114. }
  115. #endif /* _MBCS */