From 9084fa27f0f43cfa31dbc3a7ef87e2600c2dc3ca Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 18 Apr 2014 16:56:34 +0200 Subject: 1.16 --- library/zstring.cpp | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'library/zstring.cpp') diff --git a/library/zstring.cpp b/library/zstring.cpp index 35704b01..27633392 100644 --- a/library/zstring.cpp +++ b/library/zstring.cpp @@ -24,29 +24,23 @@ void testZstringForMemoryLeak() #ifdef FFS_WIN -int FreeFileSync::compareStringsWin32(const wchar_t* a, const wchar_t* b) -{ - return lstrcmpi( - a, //address of first string - b); //address of second string -} - - -//equivalent implementation, but slightly(!!!) slower: int FreeFileSync::compareStringsWin32(const wchar_t* a, const wchar_t* b, const int aCount, const int bCount) { - int rv = CompareString( - LOCALE_USER_DEFAULT, //locale identifier - NORM_IGNORECASE, //comparison-style options - a, //pointer to first string - aCount, //size, in bytes or characters, of first string - b, //pointer to second string - bCount); //size, in bytes or characters, of second string + //DON'T use lstrcmpi() here! It uses word sort, which unfortunately is NOT always a strict weak sorting function for some locales (e.g. swedish) + //Use CompareString() with "SORT_STRINGSORT" instead!!! + + const int rv = CompareString( + LOCALE_USER_DEFAULT, //locale identifier + NORM_IGNORECASE | SORT_STRINGSORT, //comparison-style options + a, //pointer to first string + aCount, //size, in bytes or characters, of first string + b, //pointer to second string + bCount); //size, in bytes or characters, of second string if (rv == 0) throw RuntimeException(wxString(wxT("Error comparing strings!"))); else - return rv - 2; + return rv - 2; //convert to C-style string compare result } #endif -- cgit