From 1935acd7a5748a73f24d97a7084066a18997dcb4 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 12 Apr 2010 00:36:22 +0000 Subject: [PATCH] Use string sort order with CompareString() in wxString::CmpNoCase(). Using the default word sort order may fail to define a strict weak order using this function, thus breaking algorithms such as std::sort which rely on its properties. It's also more consistent with the fallback manual implementation. Closes #10375. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63941 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/string.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/common/string.cpp b/src/common/string.cpp index dcac014916..f3e8c0b260 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -1079,9 +1079,15 @@ size_t wxString::find_last_not_of(const wxOtherCharType* sz, size_t nStart, int wxString::CmpNoCase(const wxString& s) const { #if defined(__WXMSW__) && !wxUSE_UNICODE_UTF8 - // prefer to use CompareString() if available as it's more efficient than - // doing it manual or even using wxStricmp() (see #10375) - switch ( ::CompareString(LOCALE_USER_DEFAULT, NORM_IGNORECASE, + // Prefer to use CompareString() if available as it's more efficient than + // doing it manually or even using wxStricmp() (see #10375) + // + // Also note that not using NORM_STRINGSORT may result in not having a + // strict weak ordering (e.g. s1 < s2 and s2 < s3 but s3 < s1) and so break + // algorithms such as std::sort that rely on it. It's also more consistent + // with the fall back version below. + switch ( ::CompareString(LOCALE_USER_DEFAULT, + NORM_IGNORECASE | SORT_STRINGSORT, m_impl.c_str(), m_impl.length(), s.m_impl.c_str(), s.m_impl.length()) ) { -- 2.45.2