home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / iswctype.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  3KB  |  108 lines

  1. /***
  2. *iswctype.c - support isw* wctype functions/macros for wide characters
  3. *
  4. *       Copyright (c) 1991-1998, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       Defines iswctype - support isw* wctype functions/macros for
  8. *       wide characters (esp. > 255).
  9. *
  10. *******************************************************************************/
  11.  
  12. #include <cruntime.h>
  13. #include <ctype.h>
  14. #include <stdio.h>
  15. #include <locale.h>
  16. #include <setlocal.h>
  17. #include <awint.h>
  18.  
  19. /*
  20.  *  Use GetStringTypeW() API so check that character type masks agree between
  21.  *  ctype.h and winnls.h
  22.  */
  23. #if _UPPER != C1_UPPER  || \
  24.         _LOWER != C1_LOWER  || \
  25.         _DIGIT != C1_DIGIT  || \
  26.         _SPACE != C1_SPACE  || \
  27.         _PUNCT != C1_PUNCT  || \
  28.         _CONTROL != C1_CNTRL
  29. #error Character type masks do not agree in ctype and winnls
  30. #endif  /* _UPPER != C1_UPPER  || \ */
  31.  
  32. /***
  33. *iswctype - support isw* wctype functions/macros.
  34. *
  35. *Purpose:
  36. *       This function is called by the isw* wctype functions/macros
  37. *       (e.g. iswalpha()) when their argument is a wide character > 255.
  38. *       It is also a standard ITSCJ (proposed) ISO routine and can be called
  39. *       by the user, even for characters < 256.
  40. *       Returns true or false depending on whether the argument satisfies
  41. *       the character class property encoded by the mask.  Returns 0 if the
  42. *       argument is WEOF.
  43. *
  44. *       NOTE: The isw* functions are neither locale nor codepage dependent.
  45. *
  46. *Entry:
  47. *       wchar_t c    - the wide character whose type is to be tested
  48. *       wchar_t mask - the mask used by the isw* functions/macros
  49. *                       corresponding to each character class property
  50. *
  51. *Exit:
  52. *       Returns non-zero if c is of the character class.
  53. *       Returns 0 if c is not of the character class.
  54. *
  55. *Exceptions:
  56. *       Returns 0 on any error.
  57. *
  58. *******************************************************************************/
  59.  
  60. int __cdecl iswctype (
  61.         wchar_t c,
  62.         wctype_t mask
  63.         )
  64. {
  65.         wint_t d;
  66.  
  67.         if (c == WEOF)
  68.             return 0;
  69.  
  70.         if (c < 256)
  71.             d = _pwctype[c];
  72.         else
  73.         {
  74.             if ( __crtGetStringTypeW(CT_CTYPE1, &c, 1, &d, 0, 0) == 0 )
  75.                 return 0;
  76.         }
  77.  
  78.         return (int)(d & mask);
  79. }
  80.  
  81.  
  82. /***
  83. *is_wctype - support obsolete name
  84. *
  85. *Purpose:
  86. *       Name changed from is_wctype to iswctype. is_wctype must be supported.
  87. *
  88. *Entry:
  89. *       wchar_t c    - the wide character whose type is to be tested
  90. *       wchar_t mask - the mask used by the isw* functions/macros
  91. *                       corresponding to each character class property
  92. *
  93. *Exit:
  94. *       Returns non-zero if c is of the character class.
  95. *       Returns 0 if c is not of the character class.
  96. *
  97. *Exceptions:
  98. *       Returns 0 on any error.
  99. *
  100. *******************************************************************************/
  101. int __cdecl is_wctype (
  102.         wchar_t c,
  103.         wctype_t mask
  104.         )
  105. {
  106.         return iswctype(c, mask);
  107. }
  108.