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

  1. /***
  2. *ismblwr - Test if character is lower case (MBCS)
  3. *
  4. *       Copyright (c) 1985-1997, Microsoft Corporation.  All rights reserved.
  5. *
  6. *Purpose:
  7. *       Test if character is lower case (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. * _ismbclower - Test if character is lower case (MBCS)
  27. *
  28. *Purpose:
  29. *       Test if the supplied character is lower case 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 character is lower case, else FALSE
  41. *
  42. *Exceptions:
  43. *
  44. *******************************************************************************/
  45.  
  46. int __cdecl _ismbclower (unsigned int c)
  47. {
  48.         if (c > 0x00FF)
  49.         {
  50.  
  51. #if defined (_WIN32)
  52.  
  53.             char buf[2];
  54.             unsigned short ctype[2] = {0};
  55.  
  56.             buf[0] = (c >> 8) & 0xFF;
  57.             buf[1] = c & 0xFF;
  58.  
  59.             /* return FALSE if not in supported MB code page */
  60.             if ( _ISNOTMBCP )
  61.                 return 0;
  62.  
  63.             /*
  64.              * Since 'c' could be two one-byte MB chars, we need room
  65.              * in the ctype return array to handle this. In this case,
  66.              * the second word in the return array will be nonzero.
  67.              */
  68.  
  69.             if (__crtGetStringTypeA (CT_CTYPE1, buf,
  70.                             2, ctype, __mbcodepage, __mblcid, TRUE) == 0)
  71.                 return 0;
  72.  
  73.             /* ensure single MB character and test for type */
  74.             return (ctype[1] == 0 && ctype[0] & (_LOWER));
  75.  
  76. #else  /* defined (_WIN32) */
  77.  
  78.             return (c >= _MBLOWERLOW1 && c <= _MBLOWERHIGH1 ||
  79.                     c >= _MBLOWERLOW2 && c <= _MBLOWERHIGH2);
  80.  
  81. #endif  /* defined (_WIN32) */
  82.  
  83.         }
  84.         else
  85.             return _mbbislower(c);
  86. }
  87.  
  88. #endif  /* _MBCS */
  89.