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.

130 lines
3.6 KiB

  1. /***
  2. *ismbalnm - Test if character is alpha numeric (MBCS)
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Test if character is alpha numeric (MBCS)
  8. *
  9. *Revision History:
  10. * 10-21-93 CFW Module created.
  11. * 11-09-93 CFW Add code page for __crtxxx().
  12. * 01-12-94 CFW Add lcid for __crtxxx().
  13. * 04-18-94 CFW Use _ALPHA rather than _UPPER|_LOWER.
  14. * 04-29-94 CFW Place c in char array.
  15. * 05-19-94 CFW Enable non-Win32.
  16. * 09-05-94 CFW Non-Win32 check for DIGITs.
  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-30-98 GJF Implemented multithread support based on threadmbcinfo
  21. * structs
  22. * 05-17-99 PML Remove all Macintosh support.
  23. *
  24. *******************************************************************************/
  25. #ifdef _MBCS
  26. #if !defined(_POSIX_)
  27. #include <windows.h>
  28. #include <awint.h>
  29. #endif /* !_POSIX_ */
  30. #include <mtdll.h>
  31. #include <cruntime.h>
  32. #include <ctype.h>
  33. #include <mbdata.h>
  34. #include <mbctype.h>
  35. #include <mbstring.h>
  36. /***
  37. * _ismbcalnum - Test if character is alpha numeric (MBCS)
  38. *
  39. *Purpose:
  40. * Test if the supplied character is alpha numeric or not.
  41. * Handles MBCS characters correctly.
  42. *
  43. * Note: Use test against 0x00FF instead of _ISLEADBYTE
  44. * to ensure that we don't call SBCS routine with a two-byte
  45. * value.
  46. *
  47. *Entry:
  48. * unsigned int c = character to test
  49. *
  50. *Exit:
  51. * Returns TRUE if c is an alpha numeric character; else FALSE
  52. *
  53. *Exceptions:
  54. *
  55. *******************************************************************************/
  56. int __cdecl _ismbcalnum(
  57. unsigned int c
  58. )
  59. {
  60. #ifdef _MT
  61. pthreadmbcinfo ptmbci = _getptd()->ptmbcinfo;
  62. if ( ptmbci != __ptmbcinfo )
  63. ptmbci = __updatetmbcinfo();
  64. #endif
  65. if (c > 0x00FF)
  66. {
  67. #if !defined(_POSIX_)
  68. char buf[2];
  69. unsigned short ctype[2] = {0};
  70. buf[0] = (c >> 8) & 0xFF;
  71. buf[1] = c & 0xFF;
  72. /* return FALSE if not in supported MB code page */
  73. #ifdef _MT
  74. if ( _ISNOTMBCP_MT(ptmbci) )
  75. #else
  76. if ( _ISNOTMBCP )
  77. #endif
  78. return 0;
  79. /*
  80. * Since 'c' could be two one-byte MB chars, we need room in the
  81. * ctype return array to handle this. In this case, the
  82. * second word in the return array will be non-zero.
  83. */
  84. if ( __crtGetStringTypeA( CT_CTYPE1,
  85. buf,
  86. 2,
  87. ctype,
  88. #ifdef _MT
  89. ptmbci->mbcodepage,
  90. ptmbci->mblcid,
  91. #else
  92. __mbcodepage,
  93. __mblcid,
  94. #endif
  95. TRUE ) == 0 )
  96. return 0;
  97. /* ensure single MB character and test for type */
  98. return (ctype[1] == 0 && ctype[0] & (_ALPHA|_DIGIT));
  99. #else /* !_POSIX_ */
  100. return ((c >= _MBDIGITLOW && c <= _MBDIGITHIGH) || _ismbcalpha(c));
  101. #endif /* !_POSIX_ */
  102. } else
  103. #ifdef _MT
  104. return __ismbbalnum_mt(ptmbci, c);
  105. #else
  106. return _ismbbalnum(c);
  107. #endif
  108. }
  109. #endif /* _MBCS */