xref: /reactos/sdk/lib/ucrt/mbstring/mbtoupr.cpp (revision e3e520d1)
1 /***
2 *mbtoupr.c - Convert character to upper case (MBCS)
3 *
4 *       Copyright (c) Microsoft Corporation.  All rights reserved.
5 *
6 *Purpose:
7 *       Convert character to upper case (MBCS)
8 *
9 *******************************************************************************/
10 #ifndef _MBCS
11     #error This file should only be compiled with _MBCS defined
12 #endif
13 
14 #include <corecrt_internal_mbstring.h>
15 #include <locale.h>
16 
17 /***
18 * _mbctoupper - Convert character to upper case (MBCS)
19 *
20 *Purpose:
21 *       If the given character is lower case, convert to upper case.
22 *       Handles MBCS chars correctly.
23 *
24 *       Note:  Use test against 0x00FF instead of _ISLEADBYTE
25 *       to ensure that we don't call SBCS routine with a two-byte
26 *       value.
27 *
28 *Entry:
29 *       unsigned int c = character to convert
30 *
31 *Exit:
32 *       Returns converted character
33 *
34 *Exceptions:
35 *
36 *******************************************************************************/
37 
38 extern "C" unsigned int __cdecl _mbctoupper_l(
39         unsigned int c,
40         _locale_t plocinfo
41         )
42 {
43         unsigned char val[2];
44         unsigned char ret[4];
45         _LocaleUpdate _loc_update(plocinfo);
46 
47         if (c > 0x00FF)
48         {
49 
50             val[0] = (c >> 8) & 0xFF;
51             val[1] = c & 0xFF;
52 
53             if ( !_ismbblead_l(val[0], _loc_update.GetLocaleT()) )
54                 return c;
55 
56 
57             if ( __acrt_LCMapStringA(
58                         _loc_update.GetLocaleT(),
59                         _loc_update.GetLocaleT()->mbcinfo->mblocalename,
60                         LCMAP_UPPERCASE,
61                         (const char *)val,
62                         2,
63                         (char *)ret,
64                         2,
65                         _loc_update.GetLocaleT()->mbcinfo->mbcodepage,
66                         TRUE ) == 0 )
67                 return c;
68 
69             c = ret[1];
70             c += ret[0] << 8;
71 
72             return c;
73 
74 
75         }
76         else
77             return (unsigned int)_mbbtoupper_l((int)c, _loc_update.GetLocaleT());
78 }
79 unsigned int (__cdecl _mbctoupper)(
80         unsigned int c
81         )
82 {
83     return _mbctoupper_l(c, nullptr);
84 }
85