Commit 54b951a4 authored by Alexandre Julliard's avatar Alexandre Julliard

Make Char{Lower,Upper}A call Char{Lower,Upper}BuffA.

Small optimization to avoid a memory allocation. Fixed sign extension in Char{Lower,Upper}A (reported by Andreas Rosenberg).
parent 6fee8c95
...@@ -112,7 +112,7 @@ SEGPTR WINAPI AnsiUpper16( SEGPTR strOrChar ) ...@@ -112,7 +112,7 @@ SEGPTR WINAPI AnsiUpper16( SEGPTR strOrChar )
CharUpperA( MapSL(strOrChar) ); CharUpperA( MapSL(strOrChar) );
return strOrChar; return strOrChar;
} }
else return toupper((char)strOrChar); else return (SEGPTR)CharUpperA( (LPSTR)strOrChar );
} }
...@@ -127,7 +127,7 @@ SEGPTR WINAPI AnsiLower16( SEGPTR strOrChar ) ...@@ -127,7 +127,7 @@ SEGPTR WINAPI AnsiLower16( SEGPTR strOrChar )
CharLowerA( MapSL(strOrChar) ); CharLowerA( MapSL(strOrChar) );
return strOrChar; return strOrChar;
} }
else return tolower((char)strOrChar); else return (SEGPTR)CharLowerA( (LPSTR)strOrChar );
} }
...@@ -360,20 +360,19 @@ BOOL WINAPI OemToCharW( LPCSTR s, LPWSTR d ) ...@@ -360,20 +360,19 @@ BOOL WINAPI OemToCharW( LPCSTR s, LPWSTR d )
/*********************************************************************** /***********************************************************************
* CharLowerA (USER32.@) * CharLowerA (USER32.@)
* FIXME: handle current locale
*/ */
LPSTR WINAPI CharLowerA(LPSTR x) LPSTR WINAPI CharLowerA(LPSTR str)
{ {
if (!HIWORD(x)) return (LPSTR)tolower((char)(int)x); if (!HIWORD(str))
{
char ch = LOWORD(str);
CharLowerBuffA( &ch, 1 );
return (LPSTR)(UINT_PTR)(BYTE)ch;
}
__TRY __TRY
{ {
LPSTR s = x; CharLowerBuffA( str, strlen(str) );
while (*s)
{
*s=tolower(*s);
s++;
}
} }
__EXCEPT(page_fault) __EXCEPT(page_fault)
{ {
...@@ -381,26 +380,25 @@ LPSTR WINAPI CharLowerA(LPSTR x) ...@@ -381,26 +380,25 @@ LPSTR WINAPI CharLowerA(LPSTR x)
return NULL; return NULL;
} }
__ENDTRY __ENDTRY
return x; return str;
} }
/*********************************************************************** /***********************************************************************
* CharUpperA (USER32.@) * CharUpperA (USER32.@)
* FIXME: handle current locale
*/ */
LPSTR WINAPI CharUpperA(LPSTR x) LPSTR WINAPI CharUpperA(LPSTR str)
{ {
if (!HIWORD(x)) return (LPSTR)toupper((char)(int)x); if (!HIWORD(str))
{
char ch = LOWORD(str);
CharUpperBuffA( &ch, 1 );
return (LPSTR)(UINT_PTR)(BYTE)ch;
}
__TRY __TRY
{ {
LPSTR s = x; CharUpperBuffA( str, strlen(str) );
while (*s)
{
*s=toupper(*s);
s++;
}
} }
__EXCEPT(page_fault) __EXCEPT(page_fault)
{ {
...@@ -408,7 +406,7 @@ LPSTR WINAPI CharUpperA(LPSTR x) ...@@ -408,7 +406,7 @@ LPSTR WINAPI CharUpperA(LPSTR x)
return NULL; return NULL;
} }
__ENDTRY __ENDTRY
return x; return str;
} }
...@@ -438,20 +436,22 @@ LPWSTR WINAPI CharUpperW(LPWSTR x) ...@@ -438,20 +436,22 @@ LPWSTR WINAPI CharUpperW(LPWSTR x)
DWORD WINAPI CharLowerBuffA( LPSTR str, DWORD len ) DWORD WINAPI CharLowerBuffA( LPSTR str, DWORD len )
{ {
DWORD lenW; DWORD lenW;
WCHAR *strW; WCHAR buffer[32];
WCHAR *strW = buffer;
if (!str) return 0; /* YES */ if (!str) return 0; /* YES */
lenW = MultiByteToWideChar(CP_ACP, 0, str, len, NULL, 0); lenW = MultiByteToWideChar(CP_ACP, 0, str, len, NULL, 0);
strW = HeapAlloc(GetProcessHeap(), 0, lenW * sizeof(WCHAR)); if (lenW > sizeof(buffer)/sizeof(WCHAR))
if(strW)
{ {
MultiByteToWideChar(CP_ACP, 0, str, len, strW, lenW); strW = HeapAlloc(GetProcessHeap(), 0, lenW * sizeof(WCHAR));
CharLowerBuffW(strW, lenW); if (!strW) return 0;
len = WideCharToMultiByte(CP_ACP, 0, strW, lenW, str, len, NULL, NULL);
HeapFree(GetProcessHeap(), 0, strW);
return len;
} }
return 0; MultiByteToWideChar(CP_ACP, 0, str, len, strW, lenW);
CharLowerBuffW(strW, lenW);
len = WideCharToMultiByte(CP_ACP, 0, strW, lenW, str, len, NULL, NULL);
if (strW != buffer) HeapFree(GetProcessHeap(), 0, strW);
return len;
} }
...@@ -473,20 +473,22 @@ DWORD WINAPI CharLowerBuffW( LPWSTR str, DWORD len ) ...@@ -473,20 +473,22 @@ DWORD WINAPI CharLowerBuffW( LPWSTR str, DWORD len )
DWORD WINAPI CharUpperBuffA( LPSTR str, DWORD len ) DWORD WINAPI CharUpperBuffA( LPSTR str, DWORD len )
{ {
DWORD lenW; DWORD lenW;
WCHAR *strW; WCHAR buffer[32];
WCHAR *strW = buffer;
if (!str) return 0; /* YES */ if (!str) return 0; /* YES */
lenW = MultiByteToWideChar(CP_ACP, 0, str, len, NULL, 0); lenW = MultiByteToWideChar(CP_ACP, 0, str, len, NULL, 0);
strW = HeapAlloc(GetProcessHeap(), 0, lenW * sizeof(WCHAR)); if (lenW > sizeof(buffer)/sizeof(WCHAR))
if(strW)
{ {
MultiByteToWideChar(CP_ACP, 0, str, len, strW, lenW); strW = HeapAlloc(GetProcessHeap(), 0, lenW * sizeof(WCHAR));
CharUpperBuffW(strW, lenW); if (!strW) return 0;
len = WideCharToMultiByte(CP_ACP, 0, strW, lenW, str, len, NULL, NULL);
HeapFree(GetProcessHeap(), 0, strW);
return len;
} }
return 0; MultiByteToWideChar(CP_ACP, 0, str, len, strW, lenW);
CharUpperBuffW(strW, lenW);
len = WideCharToMultiByte(CP_ACP, 0, strW, lenW, str, len, NULL, NULL);
if (strW != buffer) HeapFree(GetProcessHeap(), 0, strW);
return len;
} }
......
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