Leaked source code of windows server 2003
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.

151 lines
4.1 KiB

  1. /***
  2. *towlower.c - convert wide character to lower case
  3. *
  4. * Copyright (c) 1991-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Defines towlower().
  8. *
  9. *Revision History:
  10. * 10-11-91 ETC Created.
  11. * 12-10-91 ETC Updated nlsapi; added multithread.
  12. * 04-06-92 KRS Make work without _INTL also.
  13. * 01-19-93 CFW Changed LCMapString to LCMapStringW.
  14. * 04-06-93 SKS Replace _CRTAPI* with _cdecl
  15. * 06-02-93 SRW ignore _INTL if _NTSUBSET_ defined.
  16. * 06-11-93 CFW Fix error handling bug.
  17. * 09-15-93 CFW Use ANSI conformant "__" names.
  18. * 09-22-93 CFW Use __crtxxx internal NLS API wrapper.
  19. * 09-29-93 GJF Merged NT SDK and Cuda versions.
  20. * 11-09-93 CFW Add code page for __crtxxx().
  21. * 02-07-94 CFW POSIXify.
  22. * 09-06-94 CFW Remove _INTL switch.
  23. * 10-25-94 GJF Sped up for C locale. Also, added _towlower_lk.
  24. * 09-26-95 GJF New locking macro, and scheme, for functions which
  25. * reference the locale.
  26. * 04-01-96 BWT POSIX work.
  27. * 06-25-96 GJF Removed DLL_FOR_WIN32S and cleaned up the format a
  28. * wee bit.
  29. * 08-27-98 GJF Revised multithread support based on threadlocinfo
  30. * struct.
  31. *
  32. *******************************************************************************/
  33. #include <cruntime.h>
  34. #include <ctype.h>
  35. #include <stdio.h>
  36. #include <locale.h>
  37. #include <setlocal.h>
  38. #include <mtdll.h>
  39. #include <awint.h>
  40. /***
  41. *wchar_t towlower(c) - convert wide character to lower case
  42. *
  43. *Purpose:
  44. * towlower() returns the lowercase equivalent of its argument
  45. *
  46. *Entry:
  47. * c - wchar_t value of character to be converted
  48. *
  49. *Exit:
  50. * if c is an upper case letter, returns wchar_t value of lower case
  51. * representation of c. otherwise, it returns c.
  52. *
  53. *Exceptions:
  54. *
  55. *******************************************************************************/
  56. wchar_t __cdecl towlower (
  57. wchar_t c
  58. )
  59. {
  60. #if !defined(_NTSUBSET_) && !defined(_POSIX_)
  61. #ifdef _MT
  62. pthreadlocinfo ptloci = _getptd()->ptlocinfo;
  63. if ( ptloci != __ptlocinfo )
  64. ptloci = __updatetlocinfo();
  65. if ( c == WEOF )
  66. return c;
  67. if ( ptloci->lc_handle[LC_CTYPE] == _CLOCALEHANDLE )
  68. return __ascii_towlower(c);
  69. return __towlower_mt(ptloci, c);
  70. }
  71. /***
  72. *wchar_t __towlower_mt(ptloci, c) - convert wide character to lower case
  73. *
  74. *Purpose:
  75. * Multi-thread function only! Non-locking version of towlower.
  76. *
  77. *Entry:
  78. *
  79. *Exit:
  80. *
  81. *Exceptions:
  82. *
  83. *******************************************************************************/
  84. wchar_t __cdecl __towlower_mt (
  85. pthreadlocinfo ptloci,
  86. wchar_t c
  87. )
  88. {
  89. #endif /* _MT */
  90. wchar_t widechar;
  91. if (c == WEOF)
  92. return c;
  93. #ifndef _MT
  94. if ( __lc_handle[LC_CTYPE] == _CLOCALEHANDLE )
  95. return __ascii_towlower(c);
  96. #endif
  97. /* if checking case of c does not require API call, do it */
  98. if ( c < 256 ) {
  99. #ifdef _MT
  100. if ( !__iswupper_mt(ptloci, c) ) {
  101. #else
  102. if ( !iswupper(c) ) {
  103. #endif
  104. return c;
  105. }
  106. }
  107. /* convert wide char to lowercase */
  108. #ifdef _MT
  109. if ( 0 == __crtLCMapStringW( ptloci->lc_handle[LC_CTYPE],
  110. #else
  111. if ( 0 == __crtLCMapStringW( __lc_handle[LC_CTYPE],
  112. #endif
  113. LCMAP_LOWERCASE,
  114. (LPCWSTR)&c,
  115. 1,
  116. (LPWSTR)&widechar,
  117. 1,
  118. #ifdef _MT
  119. ptloci->lc_codepage ) )
  120. #else
  121. __lc_codepage ) )
  122. #endif
  123. {
  124. return c;
  125. }
  126. return widechar;
  127. #else /* _NTSUBSET_/_POSIX_ */
  128. return (iswupper(c) ? (c + (wchar_t)(L'a' - L'A')) : c);
  129. #endif /* _NTSUBSET_/_POSIX_ */
  130. }