Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

170 lines
5.3 KiB

  1. /***
  2. *wcsupr.c - routine to map lower-case characters in a wchar_t string
  3. * to upper-case
  4. *
  5. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  6. *
  7. *Purpose:
  8. * Converts all the lower case characters in a wchar_t string
  9. * to upper case, in place.
  10. *
  11. *Revision History:
  12. * 09-09-91 ETC Created from strupr.c and wcslwr.c
  13. * 04-06-92 KRS Make work without _INTL also.
  14. * 08-19-92 KRS Activate NLS support.
  15. * 08-22-92 SRW Allow INTL definition to be conditional for building ntcrt.lib
  16. * 09-02-92 SRW Get _INTL definition via ..\crt32.def
  17. * 02-16-93 CFW Optimize test for lowercase in "C" locale.
  18. * 04-06-93 SKS Replace _CRTAPI* with __cdecl
  19. * 06-02-93 SRW ignore _INTL if _NTSUBSET_ defined.
  20. * 09-15-93 CFW Use ANSI conformant "__" names.
  21. * 09-16-93 GJF Merged NT SDK and Cuda versions.
  22. * 09-22-93 CFW Use __crtxxx internal NLS API wrapper.
  23. * 11-09-93 CFW Add code page for __crtxxx().
  24. * 02-07-94 CFW POSIXify.
  25. * 09-06-94 CFW Remove _INTL switch.
  26. * 10-25-94 GJF Sped up C locale, multi-thread case.
  27. * 01-10-95 CFW Debug CRT allocs.
  28. * 09-26-95 GJF New locking macro, and scheme, for functions which
  29. * reference the locale.
  30. * 08-17-98 GJF Revised multithread support based on threadlocinfo
  31. * struct. Also, use _alloca instead of _malloc_crt if
  32. * possible.
  33. * 10-19-98 GJF Major typo, = should have been ==
  34. * 12-10-99 GB Added support for recovery from stack overflow around
  35. * _alloca().
  36. *
  37. *******************************************************************************/
  38. #ifndef _POSIX_
  39. #include <cruntime.h>
  40. #include <string.h>
  41. #include <malloc.h>
  42. #include <locale.h>
  43. #include <ctype.h>
  44. #include <setlocal.h>
  45. #include <mtdll.h>
  46. #include <awint.h>
  47. #include <dbgint.h>
  48. /***
  49. *wchar_t *_wcsupr(string) - map lower-case characters in a string to upper-case
  50. *
  51. *Purpose:
  52. * wcsupr converts lower-case characters in a null-terminated wchar_t
  53. * string to their upper-case equivalents. The result may be longer or
  54. * shorter than the original string. Assumes enough space in string
  55. * to hold the result.
  56. *
  57. *Entry:
  58. * wchar_t *wsrc - wchar_t string to change to upper case
  59. *
  60. *Exit:
  61. * input string address
  62. *
  63. *Exceptions:
  64. * on an error, the original string is unaltered
  65. *
  66. *******************************************************************************/
  67. wchar_t * __cdecl _wcsupr (
  68. wchar_t * wsrc
  69. )
  70. {
  71. #ifndef _NTSUBSET_
  72. wchar_t *p; /* traverses string for C locale conversion */
  73. wchar_t *wdst; /* wide version of string in alternate case */
  74. int dstlen; /* len of wdst string, wide chars, with null */
  75. int malloc_flag = 0;
  76. #ifdef _MT
  77. pthreadlocinfo ptloci = _getptd()->ptlocinfo;
  78. if ( ptloci != __ptlocinfo )
  79. ptloci = __updatetlocinfo();
  80. if ( ptloci->lc_handle[LC_CTYPE] == _CLOCALEHANDLE ) {
  81. #else
  82. if ( __lc_handle[LC_CTYPE] == _CLOCALEHANDLE ) {
  83. #endif
  84. for ( p = wsrc ; *p ; p++ )
  85. {
  86. if ( (*p >= (wchar_t)L'a') && (*p <= (wchar_t)L'z') )
  87. *p = *p - (L'a' - L'A');
  88. }
  89. return(wsrc);
  90. } /* C locale */
  91. /* Inquire size of wdst string */
  92. #ifdef _MT
  93. if ( (dstlen = __crtLCMapStringW( ptloci->lc_handle[LC_CTYPE],
  94. #else
  95. if ( (dstlen = __crtLCMapStringW( __lc_handle[LC_CTYPE],
  96. #endif
  97. LCMAP_UPPERCASE,
  98. wsrc,
  99. -1,
  100. NULL,
  101. 0,
  102. #ifdef _MT
  103. ptloci->lc_codepage )) == 0 )
  104. #else
  105. __lc_codepage )) == 0 )
  106. #endif
  107. return(wsrc);
  108. /* Allocate space for wdst */
  109. __try {
  110. wdst = (wchar_t *)_alloca(dstlen * sizeof(wchar_t));
  111. }
  112. __except( EXCEPTION_EXECUTE_HANDLER ) {
  113. _resetstkoflw();
  114. wdst = NULL;
  115. }
  116. if ( wdst == NULL ) {
  117. wdst = (wchar_t *)_malloc_crt(dstlen * sizeof(wchar_t));
  118. malloc_flag++;
  119. }
  120. /* Map wrc string to wide-character wdst string in alternate case */
  121. if ( (wdst != NULL) &&
  122. #ifdef _MT
  123. (__crtLCMapStringW( ptloci->lc_handle[LC_CTYPE],
  124. #else
  125. (__crtLCMapStringW( __lc_handle[LC_CTYPE],
  126. #endif
  127. LCMAP_UPPERCASE,
  128. wsrc,
  129. -1,
  130. wdst,
  131. dstlen,
  132. #ifdef _MT
  133. ptloci->lc_codepage ) != 0) )
  134. #else
  135. __lc_codepage ) != 0) )
  136. #endif
  137. /* Copy wdst string to user string */
  138. wcscpy (wsrc, wdst);
  139. if ( malloc_flag )
  140. _free_crt(wdst);
  141. #else
  142. wchar_t * p;
  143. for (p=wsrc; *p; ++p)
  144. {
  145. if (L'a' <= *p && *p <= L'z')
  146. *p += (wchar_t)(L'A' - L'a');
  147. }
  148. #endif
  149. return(wsrc);
  150. }
  151. #endif /* _POSIX_ */