ReactOS 0.4.16-dev-889-g9563c07
towlower.cpp
Go to the documentation of this file.
1/***
2*towlower.cpp - convert wide character to lower case
3*
4* Copyright (c) Microsoft Corporation. All rights reserved.
5*
6*Purpose:
7* Defines towlower().
8*
9*******************************************************************************/
10#include <corecrt_internal.h>
11#include <ctype.h>
12#include <locale.h>
13
14/***
15*wint_t _towlower_l(c, ptloci) - convert wide character to lower case
16*
17*Purpose:
18* Multi-thread function only! Non-locking version of towlower.
19*
20*Entry:
21*
22*Exit:
23*
24*Exceptions:
25*
26*******************************************************************************/
27
29 wint_t const c,
31 )
32{
33 if (c == WEOF)
34 {
35 return c;
36 }
37
38 _LocaleUpdate _loc_update(plocinfo);
39 auto const locinfo = _loc_update.GetLocaleT()->locinfo;
40
41 if (locinfo->_public._locale_lc_codepage == CP_UTF8)
42 {
43 // For 128 <= c < 256, the tolower map would consider the wide character as it is in UTF-8, not UTF-16.
44 // Below 128, UTF-8 and UTF-16 have the same encodings, so we can use the table.
45 if (c < 128)
46 {
47 return _towlower_fast_internal(static_cast<unsigned char>(c), _loc_update.GetLocaleT());
48 }
49 }
50 else
51 {
52 // For 128 <= c < 256, the tolower map will consider the wide character as it would be in the current narrow code page,
53 // which can lead to unexpected behavior. This behavior is maintained for backwards compatibility.
54 if (c < 256)
55 {
56 return _towlower_fast_internal(static_cast<unsigned char>(c), _loc_update.GetLocaleT());
57 }
58
59 if (locinfo->locale_name[LC_CTYPE] == nullptr)
60 {
61 // If the locale is C, then the only characters that would be transformed are <256
62 // and have been processed already.
63 return c;
64 }
65 }
66
67 wint_t widechar;
68 if (0 == __acrt_LCMapStringW(
69 locinfo->locale_name[LC_CTYPE],
71 (LPCWSTR)&c,
72 1,
73 (LPWSTR)&widechar,
74 1))
75 {
76 return c;
77 }
78
79 return widechar;
80}
81
82/***
83*wint_t towlower(c) - convert wide character to lower case
84*
85*Purpose:
86* towlower() returns the lowercase equivalent of its argument
87*
88*Entry:
89* c - wint_t value of character to be converted
90*
91*Exit:
92* if c is an upper case letter, returns wint_t value of lower case
93* representation of c. otherwise, it returns c.
94*
95*Exceptions:
96*
97*******************************************************************************/
98
100 wint_t c
101 )
102{
103
104 return _towlower_l(c, nullptr);
105}
int __cdecl __acrt_LCMapStringW(LPCWSTR const locale_name, DWORD const map_flags, LPCWSTR const source, int source_count, LPWSTR const destination, int const destination_count)
int wint_t
Definition: _apple.h:38
#define __cdecl
Definition: accygwin.h:79
_Check_return_ __forceinline wint_t _towlower_fast_internal(_In_ unsigned char const c, _In_ _locale_t const locale)
const GLubyte * c
Definition: glext.h:8905
#define LC_CTYPE
Definition: locale.h:19
_locale_t plocinfo
Definition: ismbbyte.cpp:75
#define c
Definition: ke_i.h:80
else locinfo
Definition: scanf.h:159
#define WEOF
Definition: conio.h:185
#define CP_UTF8
Definition: nls.h:20
#define towlower(c)
Definition: wctype.h:97
wint_t __cdecl _towlower_l(wint_t const c, _locale_t const plocinfo)
Definition: towlower.cpp:28
#define LCMAP_LOWERCASE
Definition: winnls.h:186
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185