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.

105 lines
2.8 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-1992, 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. * 06-02-93 SRW ignore _INTL if _NTSUBSET_ defined.
  19. *
  20. *******************************************************************************/
  21. #include <windows.h>
  22. #include <cruntime.h>
  23. #include <string.h>
  24. #include <malloc.h>
  25. #include <locale.h>
  26. #include <ctype.h>
  27. #include <setlocal.h>
  28. #include <os2dll.h>
  29. /***
  30. *wchar_t *_wcsupr(string) - map lower-case characters in a string to upper-case
  31. *
  32. *Purpose:
  33. * wcsupr converts lower-case characters in a null-terminated wchar_t
  34. * string to their upper-case equivalents. The result may be longer or
  35. * shorter than the original string. Assumes enough space in string
  36. * to hold the result.
  37. *
  38. *Entry:
  39. * wchar_t *wsrc - wchar_t string to change to upper case
  40. *
  41. *Exit:
  42. * input string address
  43. *
  44. *Exceptions:
  45. * on an error, the original string is unaltered
  46. *
  47. *******************************************************************************/
  48. wchar_t * _CALLTYPE1 _wcsupr (
  49. wchar_t * wsrc
  50. )
  51. {
  52. #if defined(_INTL) && !defined(_NTSUBSET_)
  53. wchar_t *p; /* traverses string for C locale conversion */
  54. wchar_t *wdst = NULL; /* wide version of string in alternate case */
  55. int srclen; /* general purpose length of source string */
  56. int dstlen; /* len of wdst string, wide chars, no null */
  57. _mlock (_LC_CTYPE_LOCK);
  58. if (_lc_handle[LC_CTYPE] == _CLOCALEHANDLE) {
  59. _munlock (_LC_CTYPE_LOCK);
  60. for (p=wsrc; *p; p++)
  61. {
  62. if (*p >= (wchar_t)L'a' && *p <= (wchar_t)L'z')
  63. *p = *p - (L'a' - L'A');
  64. }
  65. return (wsrc);
  66. } /* C locale */
  67. /* Inquire size of wdst string */
  68. srclen = wcslen(wsrc) + 1;
  69. if ((dstlen=LCMapStringW(_lc_handle[LC_CTYPE], LCMAP_UPPERCASE, wsrc,
  70. srclen, wdst, 0)) == 0)
  71. goto error_cleanup;
  72. /* Allocate space for wdst */
  73. if ((wdst = (wchar_t *) malloc(dstlen*sizeof(wchar_t))) == NULL)
  74. goto error_cleanup;
  75. /* Map wrc string to wide-character wdst string in alternate case */
  76. if (LCMapStringW(_lc_handle[LC_CTYPE], LCMAP_UPPERCASE, wsrc,
  77. srclen, wdst, dstlen) == 0)
  78. goto error_cleanup;
  79. /* Copy wdst string to user string */
  80. wcscpy (wsrc, wdst);
  81. error_cleanup:
  82. _munlock (_LC_CTYPE_LOCK);
  83. free (wdst);
  84. #else
  85. wchar_t * p;
  86. for (p=wsrc; *p; ++p)
  87. {
  88. if (L'a' <= *p && *p <= L'z')
  89. *p += (wchar_t)(L'A' - L'a');
  90. }
  91. #endif /* _INTL */
  92. return (wsrc);
  93. }