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

  1. /***
  2. *mbtoupr.c - Convert character to upper case (MBCS)
  3. *
  4. *   Copyright (c) 1985-1997, Microsoft Corporation.  All rights reserved.
  5. *
  6. *Purpose:
  7. *   Convert character to upper 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. * _mbctoupper - Convert character to upper case (MBCS)
  25. *
  26. *Purpose:
  27. *   If the given character is lower case, convert to upper case.
  28. *   Handles MBCS chars correctly.
  29. *
  30. *   Note:  Use test against 0x00FF instead of _ISLEADBYTE
  31. *   to ensure that we don't call SBCS routine with a two-byte
  32. *   value.
  33. *
  34. *Entry:
  35. *   unsigned int c = character to convert
  36. *
  37. *Exit:
  38. *   Returns converted character
  39. *
  40. *Exceptions:
  41. *
  42. *******************************************************************************/
  43.  
  44. unsigned int __cdecl _mbctoupper(unsigned int c)
  45. {
  46.     unsigned char val[2];
  47. #if defined (_WIN32)
  48.     unsigned char ret[4];
  49. #endif  /* defined (_WIN32) */
  50.  
  51.     if (c > 0x00FF)
  52.     {
  53.         val[0] = (c >> 8) & 0xFF;
  54.         val[1] = c & 0xFF;
  55.  
  56.         if (!_ismbblead(val[0]))
  57.             return c;
  58.  
  59. #if defined (_WIN32)
  60.  
  61.         if (__crtLCMapStringA(__mblcid, LCMAP_UPPERCASE, val, 2,
  62.                               ret, 2, __mbcodepage, TRUE) == 0)
  63.             return c;
  64.  
  65.         c = ret[1];
  66.         c += ret[0] << 8;
  67.  
  68.         return c;
  69.  
  70. #else  /* defined (_WIN32) */
  71.  
  72.         if (c >= _MBLOWERLOW1 && c <= _MBLOWERHIGH1)
  73.             c -= _MBCASEDIFF1;
  74.         else if (c >= _MBLOWERLOW2 && c <= _MBLOWERHIGH2)
  75.             c -= _MBCASEDIFF2;
  76.  
  77.         return c;
  78.  
  79. #endif  /* defined (_WIN32) */
  80.  
  81.     }
  82.     else
  83.         return (unsigned int)_mbbtoupper((int)c);
  84. }
  85.  
  86. #endif  /* _MBCS */
  87.