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

  1. /***
  2. *ismbalnm - Test if character is alpha numeric (MBCS)
  3. *
  4. *       Copyright (c) 1985-1997, Microsoft Corporation.  All rights reserved.
  5. *
  6. *Purpose:
  7. *       Test if character is alpha numeric (MBCS)
  8. *
  9. *******************************************************************************/
  10.  
  11. #ifdef _MBCS
  12.  
  13. #if defined (_WIN32)
  14. #include <windows.h>
  15. #include <awint.h>
  16. #endif  /* defined (_WIN32) */
  17.  
  18. #include <cruntime.h>
  19. #include <ctype.h>
  20. #include <mbdata.h>
  21. #include <mbctype.h>
  22. #include <mbstring.h>
  23.  
  24.  
  25. /***
  26. * _ismbcalnum - Test if character is alpha numeric (MBCS)
  27. *
  28. *Purpose:
  29. *       Test if the supplied character is alpha numeric or not.
  30. *       Handles MBCS characters correctly.
  31. *
  32. *       Note:  Use test against 0x00FF instead of _ISLEADBYTE
  33. *       to ensure that we don't call SBCS routine with a two-byte
  34. *       value.
  35. *
  36. *Entry:
  37. *       unsigned int c = character to test
  38. *
  39. *Exit:
  40. *       Returns TRUE if c is an alpha numeric character; else FALSE
  41. *
  42. *Exceptions:
  43. *
  44. *******************************************************************************/
  45.  
  46. int __cdecl _ismbcalnum(
  47.         unsigned int c
  48.         )
  49. {
  50.         if (c > 0x00FF)
  51.         {
  52.  
  53. #if defined (_WIN32)
  54.  
  55.             char buf[2];
  56.             unsigned short ctype[2] = {0};
  57.  
  58.             buf[0] = (c >> 8) & 0xFF;
  59.             buf[1] = c & 0xFF;
  60.  
  61.             /* return FALSE if not in supported MB code page */
  62.             if ( _ISNOTMBCP )
  63.                 return 0;
  64.  
  65.             /*
  66.             * Since 'c' could be two one-byte MB chars, we need room in the
  67.             * ctype return array to handle this. In this case, the
  68.             * second word in the return array will be non-zero.
  69.             */
  70.  
  71.             if (__crtGetStringTypeA (CT_CTYPE1, buf,
  72.                     2, ctype, __mbcodepage, __mblcid, TRUE) == 0)
  73.                 return 0;
  74.  
  75.             /* ensure single MB character and test for type */
  76.             return (ctype[1] == 0 && ctype[0] & (_ALPHA|_DIGIT));
  77.  
  78. #else  /* defined (_WIN32) */
  79.  
  80.             return ((c >= _MBDIGITLOW && c <= _MBDIGITHIGH) || _ismbcalpha(c));
  81.  
  82. #endif  /* defined (_WIN32) */
  83.  
  84.         } else
  85.  
  86.             return _ismbbalnum(c);
  87. }
  88.  
  89. #endif  /* _MBCS */
  90.