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.

126 lines
3.4 KiB

  1. /***
  2. *ismbdgt.c - Test if character is a digit (MBCS)
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Test if character is a digit (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-29-94 CFW Place c in char array.
  15. * 05-17-94 CFW Enable non-Win32.
  16. * 03-16-97 RDK Added error flag to __crtGetStringTypeA.
  17. * 09-11-97 GJF Replaced __mbcodepage == 0 with _ISNOTMBCP.
  18. * 09-26-97 BWT Fix POSIX
  19. * 03-31-98 GJF Implemented multithread support based on threadmbcinfo
  20. * structs
  21. * 05-17-99 PML Remove all Macintosh support.
  22. * 06-03-00 PML Don't get mbcinfo if not DBCS (vs7#116057).
  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. * _ismbcdigit - Test if character is a digit (MBCS)
  38. *
  39. *Purpose:
  40. * Tests the character to see if it is a digit.
  41. * Handles MBCS chars 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 character is a digit, else FALSE
  52. *
  53. *Exceptions:
  54. *
  55. *******************************************************************************/
  56. int __cdecl _ismbcdigit(
  57. unsigned int c
  58. )
  59. {
  60. if (c > 0x00FF)
  61. {
  62. #if !defined(_POSIX_)
  63. char buf[2];
  64. unsigned short ctype[2] = {0};
  65. #ifdef _MT
  66. pthreadmbcinfo ptmbci = _getptd()->ptmbcinfo;
  67. if ( ptmbci != __ptmbcinfo )
  68. ptmbci = __updatetmbcinfo();
  69. #endif
  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] & (_DIGIT));
  99. #else /* !_POSIX */
  100. return ( (c >= _MBDIGITLOW) && (c <= _MBDIGITHIGH) ) ;
  101. #endif /* !_POSIX */
  102. } else
  103. return isdigit(c);
  104. }
  105. #endif /* _MBCS */