From 0d6802dcc5332faf4e6883cfd50d258a1741169d Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Mon, 9 Mar 2020 14:30:42 +0100 Subject: [PATCH] ntdll: Use the NLS case mapping table for towlower/towupper. Signed-off-by: Alexandre Julliard --- dlls/ntdll/locale.c | 19 +++++++++++++++++++ dlls/ntdll/tests/string.c | 15 +++++++++++++++ dlls/ntdll/wcstring.c | 18 ------------------ 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/dlls/ntdll/locale.c b/dlls/ntdll/locale.c index 8833cfa712c..8334de172d8 100644 --- a/dlls/ntdll/locale.c +++ b/dlls/ntdll/locale.c @@ -1572,6 +1572,25 @@ NTSTATUS WINAPI RtlUpcaseUnicodeToOemN( char *dst, DWORD dstlen, DWORD *reslen, } +/********************************************************************* + * towlower (NTDLL.@) + */ +WCHAR __cdecl NTDLL_towlower( WCHAR ch ) +{ + if (ch >= 0x100) return ch; + return casemap( nls_info.LowerCaseTable, ch ); +} + + +/********************************************************************* + * towupper (NTDLL.@) + */ +WCHAR __cdecl NTDLL_towupper( WCHAR ch ) +{ + return casemap( nls_info.UpperCaseTable, ch ); +} + + /****************************************************************** * RtlLocaleNameToLcid (NTDLL.@) */ diff --git a/dlls/ntdll/tests/string.c b/dlls/ntdll/tests/string.c index 548c84fb1de..b9dfda7c194 100644 --- a/dlls/ntdll/tests/string.c +++ b/dlls/ntdll/tests/string.c @@ -33,6 +33,7 @@ static NTSTATUS (WINAPI *pRtlUnicodeStringToAnsiString)(STRING *, const UNICODE_ static VOID (WINAPI *pRtlFreeAnsiString)(PSTRING); static BOOLEAN (WINAPI *pRtlCreateUnicodeStringFromAsciiz)(PUNICODE_STRING,LPCSTR); static VOID (WINAPI *pRtlFreeUnicodeString)(PUNICODE_STRING); +static WCHAR (WINAPI *pRtlUpcaseUnicodeChar)(WCHAR); static int (__cdecl *patoi)(const char *); static LONG (__cdecl *patol)(const char *); @@ -54,6 +55,8 @@ static LPWSTR (__cdecl *p_ui64tow)(ULONGLONG, LPWSTR, INT); static LPWSTR (__cdecl *p_wcslwr)(LPWSTR); static LPWSTR (__cdecl *p_wcsupr)(LPWSTR); +static WCHAR (__cdecl *ptowlower)(WCHAR); +static WCHAR (__cdecl *ptowupper)(WCHAR); static LPWSTR (__cdecl *pwcschr)(LPCWSTR, WCHAR); static LPWSTR (__cdecl *pwcsrchr)(LPCWSTR, WCHAR); @@ -78,6 +81,7 @@ static void InitFunctionPtrs(void) X(RtlFreeAnsiString); X(RtlCreateUnicodeStringFromAsciiz); X(RtlFreeUnicodeString); + X(RtlUpcaseUnicodeChar); X(atoi); X(atol); X(_atoi64); @@ -96,6 +100,8 @@ static void InitFunctionPtrs(void) X(_ui64tow); X(_wcslwr); X(_wcsupr); + X(towlower); + X(towupper); X(wcschr); X(wcsrchr); X(qsort); @@ -1151,6 +1157,7 @@ static void test_wcslwrupr(void) static WCHAR teststringW[] = {'a','b','r','a','c','a','d','a','b','r','a',0}; static WCHAR emptyW[] = {0}; static const WCHAR constemptyW[] = {0}; + int i; if (0) /* crashes on native */ { @@ -1166,6 +1173,14 @@ static void test_wcslwrupr(void) ok(p_wcsupr(emptyW) == emptyW, "p_wcsupr returned different string\n"); ok(p_wcslwr((LPWSTR)constemptyW) == constemptyW, "p_wcslwr returned different string\n"); ok(p_wcsupr((LPWSTR)constemptyW) == constemptyW, "p_wcsupr returned different string\n"); + + for (i = 0; i < 65536; i++) + { + WCHAR lwr = ((i >= 'A' && i <= 'Z') || (i >= 0xc0 && i <= 0xd6) || (i >= 0xd8 && i <= 0xde)) ? i + 32 : i; + WCHAR upr = pRtlUpcaseUnicodeChar( i ); + ok( ptowlower( i ) == lwr, "%04x: towlower got %04x expected %04x\n", i, ptowlower( i ), lwr ); + ok( ptowupper( i ) == upr, "%04x: towupper got %04x expected %04x\n", i, ptowupper( i ), upr ); + } } static int __cdecl intcomparefunc(const void *a, const void *b) diff --git a/dlls/ntdll/wcstring.c b/dlls/ntdll/wcstring.c index acdb33ac240..fe18af71705 100644 --- a/dlls/ntdll/wcstring.c +++ b/dlls/ntdll/wcstring.c @@ -69,24 +69,6 @@ LPWSTR __cdecl NTDLL__wcsupr( LPWSTR str ) } -/********************************************************************* - * towlower (NTDLL.@) - */ -WCHAR __cdecl NTDLL_towlower( WCHAR ch ) -{ - return tolowerW(ch); -} - - -/********************************************************************* - * towupper (NTDLL.@) - */ -WCHAR __cdecl NTDLL_towupper( WCHAR ch ) -{ - return toupperW(ch); -} - - /*********************************************************************** * wcscat (NTDLL.@) */