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

  1. /***
  2. *mbtolwr.c - Convert character to lower case (MBCS).
  3. *
  4. *   Copyright (c) 1985-1997, Microsoft Corporation.  All rights reserved.
  5. *
  6. *Purpose:
  7. *   Convert character to lower case (MBCS).
  8. *
  9. *******************************************************************************/
  10.  
  11. #ifdef _MBCS
  12.  
  13. #if defined (_WIN32)
  14. #include <awint.h>
  15. #endif  /* defined (_WIN32) */
  16.  
  17. #include <cruntime.h>
  18. #include <ctype.h>
  19. #include <mbdata.h>
  20. #include <mbctype.h>
  21. #include <mbstring.h>
  22.  
  23.  
  24. /***
  25. * _mbctolower - Convert character to lower case (MBCS)
  26. *
  27. *Purpose:
  28. *   If the given character is upper case, convert it to lower case.
  29. *   Handles MBCS characters correctly.
  30. *
  31. *   Note:  Use test against 0x00FF instead of _ISLEADBYTE
  32. *   to ensure that we don't call SBCS routine with a two-byte
  33. *   value.
  34. *
  35. *Entry:
  36. *   unsigned int c = character to convert
  37. *
  38. *Exit:
  39. *   Returns converted character
  40. *
  41. *Exceptions:
  42. *
  43. *******************************************************************************/
  44.  
  45. unsigned int __cdecl _mbctolower (unsigned int c)
  46. {
  47.     unsigned char val[2];
  48. #if defined (_WIN32)
  49.     unsigned char ret[4];
  50. #endif  /* defined (_WIN32) */
  51.  
  52.     if (c > 0x00FF)
  53.     {
  54.         val[0] = (c >> 8) & 0xFF;
  55.         val[1] = c & 0xFF;
  56.  
  57.         if (!_ismbblead(val[0]))
  58.             return c;
  59.  
  60. #if defined (_WIN32)
  61.  
  62.         if (__crtLCMapStringA(__mblcid, LCMAP_LOWERCASE, val, 2,
  63.                               ret, 2, __mbcodepage, TRUE) == 0)
  64.             return c;
  65.  
  66.         c = ret[1];
  67.         c += ret[0] << 8;
  68.  
  69.         return c;
  70.  
  71. #else  /* defined (_WIN32) */
  72.  
  73.         if (c >= _MBUPPERLOW1 && c <= _MBUPPERHIGH1)
  74.             c += _MBCASEDIFF1;
  75.         else if (c >= _MBUPPERLOW2 && c <= _MBUPPERHIGH2)
  76.             c += _MBCASEDIFF2;
  77.  
  78.         return c;
  79.  
  80. #endif  /* defined (_WIN32) */
  81.  
  82.     }
  83.     else
  84.             return (unsigned int)_mbbtolower((int)c);
  85. }
  86.  
  87. #endif  /* _MBCS */
  88.