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.

128 lines
3.4 KiB

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