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

  1. /***
  2. *towupper.c - convert wide character to upper case
  3. *
  4. *       Copyright (c) 1991-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       Defines towupper().
  8. *
  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 <mtdll.h>
  18. #include <awint.h>
  19.  
  20. /***
  21. *wchar_t towupper(c) - convert wide character to upper case
  22. *
  23. *Purpose:
  24. *       towupper() returns the uppercase equivalent of its argument
  25. *
  26. *Entry:
  27. *       c - wchar_t value of character to be converted
  28. *
  29. *Exit:
  30. *       if c is a lower case letter, returns wchar_t value of upper case
  31. *       representation of c. otherwise, it returns c.
  32. *
  33. *Exceptions:
  34. *
  35. *******************************************************************************/
  36.  
  37. wchar_t __cdecl towupper (
  38.         wchar_t c
  39.         )
  40. {
  41.  
  42. #ifdef _MT
  43.  
  44.         int local_lock_flag;
  45.  
  46.         if (__lc_handle[LC_CTYPE] == _CLOCALEHANDLE)
  47.         {
  48.             if ( (c >= L'a') && (c <= L'z') )
  49.                 c = c - L'a' + L'A';
  50.             return c;
  51.         }
  52.  
  53.         _lock_locale( local_lock_flag )
  54.  
  55.         c = _towupper_lk(c);
  56.  
  57.         _unlock_locale( local_lock_flag )
  58.  
  59.         return c;
  60. }
  61.  
  62. /***
  63. *wchar_t _towupper_lk(c) - convert wide character to upper case
  64. *
  65. *Purpose:
  66. *       Multi-thread function only! Non-locking version of towupper.
  67. *
  68. *Entry:
  69. *
  70. *Exit:
  71. *
  72. *Exceptions:
  73. *
  74. *******************************************************************************/
  75.  
  76. wchar_t __cdecl _towupper_lk (
  77.         wchar_t c
  78.         )
  79. {
  80.  
  81. #endif  /* _MT */
  82.  
  83.         wchar_t widechar;
  84.  
  85.         if (c == WEOF)
  86.             return c;
  87.  
  88.         if (__lc_handle[LC_CTYPE] == _CLOCALEHANDLE) {
  89.             if ( (c >= L'a') && (c <= L'z') )
  90.                 c = c - L'a' + L'A';
  91.             return c;
  92.         }
  93.  
  94.         /* if checking case of c does not require API call, do it */
  95.         if (c < 256) {
  96.             if (!iswlower(c)) {
  97.                 return c;
  98.             }
  99.         }
  100.  
  101.         /* convert wide char to uppercase */
  102.         if ( 0 == __crtLCMapStringW( __lc_handle[LC_CTYPE],
  103.                                      LCMAP_UPPERCASE,
  104.                                      (LPCWSTR)&c,
  105.                                      1,
  106.                                      (LPWSTR)&widechar,
  107.                                      1,
  108.                                      0) )
  109.         {
  110.             return c;
  111.         }
  112.  
  113.         return widechar;
  114.  
  115. }
  116.