1 /*** 2 *mbtolwr.c - Convert character to lower case (MBCS). 3 * 4 * Copyright (c) Microsoft Corporation. All rights reserved. 5 * 6 *Purpose: 7 * Convert character to lower 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 /*** 19 * _mbctolower - Convert character to lower case (MBCS) 20 * 21 *Purpose: 22 * If the given character is upper case, convert it to lower case. 23 * Handles MBCS characters correctly. 24 * 25 * Note: Use test against 0x00FF instead of _ISLEADBYTE 26 * to ensure that we don't call SBCS routine with a two-byte 27 * value. 28 * 29 *Entry: 30 * unsigned int c = character to convert 31 * 32 *Exit: 33 * Returns converted character 34 * 35 *Exceptions: 36 * 37 *******************************************************************************/ 38 39 extern "C" unsigned int __cdecl _mbctolower_l ( 40 unsigned int c, 41 _locale_t plocinfo 42 ) 43 { 44 unsigned char val[2]; 45 unsigned char ret[4]; 46 _LocaleUpdate _loc_update(plocinfo); 47 48 if (c > 0x00FF) 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_LOWERCASE, 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)_mbbtolower_l((int)c, _loc_update.GetLocaleT()); 78 } 79 80 extern "C" unsigned int (__cdecl _mbctolower) ( 81 unsigned int c 82 ) 83 { 84 return _mbctolower_l(c, nullptr); 85 } 86