Commit 28cc0b8b authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

msvcrt: Improve toupper_l implementation.

parent 13f6194b
...@@ -339,37 +339,42 @@ int CDECL MSVCRT___iscsymf(int c) ...@@ -339,37 +339,42 @@ int CDECL MSVCRT___iscsymf(int c)
int CDECL MSVCRT__toupper_l(int c, MSVCRT__locale_t locale) int CDECL MSVCRT__toupper_l(int c, MSVCRT__locale_t locale)
{ {
MSVCRT_pthreadlocinfo locinfo; MSVCRT_pthreadlocinfo locinfo;
unsigned char str[2], *p = str;
WCHAR wide, upper;
if(!locale) if(!locale)
locinfo = get_locinfo(); locinfo = get_locinfo();
else else
locinfo = locale->locinfo; locinfo = locale->locinfo;
if(c < 256) if((unsigned)c < 256)
return locinfo->pcumap[(unsigned char)c]; return locinfo->pcumap[c];
if(locinfo->pctype[(c>>8)&255] & MSVCRT__LEADBYTE) if(locinfo->pctype[(c>>8)&255] & MSVCRT__LEADBYTE)
{
WCHAR wide, upper;
char str[2], *p = str;
*p++ = (c>>8) & 255; *p++ = (c>>8) & 255;
*p++ = c & 255; else {
*MSVCRT__errno() = MSVCRT_EILSEQ;
if(!MultiByteToWideChar(locinfo->lc_codepage, str[1] = 0;
MB_ERR_INVALID_CHARS, str, 2, &wide, 1)) }
return c; *p++ = c & 255;
upper = toupperW(wide); if(!MultiByteToWideChar(locinfo->lc_codepage,
if(upper == wide) MB_ERR_INVALID_CHARS, (char*)str, p-str, &wide, 1))
return c; return c;
WideCharToMultiByte(locinfo->lc_codepage, 0, upper = toupperW(wide);
&upper, 1, str, 2, NULL, NULL); if(upper == wide)
return str[0] + (str[1]<<8);
switch(WideCharToMultiByte(locinfo->lc_codepage, 0,
&upper, 1, (char*)str, 2, NULL, NULL)) {
case 0:
return c;
case 1:
return str[0];
default:
return str[0] + (str[1]<<8); return str[0] + (str[1]<<8);
} }
return c;
} }
/********************************************************************* /*********************************************************************
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment