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)
int CDECL MSVCRT__toupper_l(int c, MSVCRT__locale_t locale)
{
MSVCRT_pthreadlocinfo locinfo;
unsigned char str[2], *p = str;
WCHAR wide, upper;
if(!locale)
locinfo = get_locinfo();
else
locinfo = locale->locinfo;
if(c < 256)
return locinfo->pcumap[(unsigned char)c];
if((unsigned)c < 256)
return locinfo->pcumap[c];
if(locinfo->pctype[(c>>8)&255] & MSVCRT__LEADBYTE)
{
WCHAR wide, upper;
char str[2], *p = str;
*p++ = (c>>8) & 255;
*p++ = c & 255;
if(!MultiByteToWideChar(locinfo->lc_codepage,
MB_ERR_INVALID_CHARS, str, 2, &wide, 1))
return c;
else {
*MSVCRT__errno() = MSVCRT_EILSEQ;
str[1] = 0;
}
*p++ = c & 255;
upper = toupperW(wide);
if(upper == wide)
return c;
if(!MultiByteToWideChar(locinfo->lc_codepage,
MB_ERR_INVALID_CHARS, (char*)str, p-str, &wide, 1))
return c;
WideCharToMultiByte(locinfo->lc_codepage, 0,
&upper, 1, str, 2, NULL, NULL);
upper = toupperW(wide);
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 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