]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/string.cpp
Fix wxGTK1 link after toolbar files renaming.
[wxWidgets.git] / src / common / string.cpp
index f5a46007a880a4ed2be929490a45d2bb84de2fbc..f3e8c0b2605001575d1cbbf725356aa4011e5ab9 100644 (file)
     #define wxStringStrlen   wxStrlen
 #endif
 
-// ----------------------------------------------------------------------------
-// global variables
-// ----------------------------------------------------------------------------
-
+// define a function declared in wx/buffer.h here as we don't have buffer.cpp
+// and don't want to add it just because of this simple function
 namespace wxPrivate
 {
 
-static UntypedBufferData s_untypedNullData(NULL, 0);
+// wxXXXBuffer classes can be (implicitly) used during global statics
+// initialization so wrap the status UntypedBufferData variable in a function
+// to make it safe to access it even before all global statics are initialized
+UntypedBufferData *GetUntypedNullData()
+{
+    static UntypedBufferData s_untypedNullData(NULL, 0);
 
-UntypedBufferData * const untypedNullDataPtr = &s_untypedNullData;
+    return &s_untypedNullData;
+}
 
 } // namespace wxPrivate
 
@@ -1075,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()) )
     {
@@ -1632,14 +1642,14 @@ int wxString::Find(wxUniChar ch, bool bFromEnd) const
     const wxStringCharType *start = wx_str();                               \
     wxStringCharType *end;
 
+// notice that we return false without modifying the output parameter at all if
+// nothing could be parsed but we do modify it and return false then if we did
+// parse something successfully but not the entire string
 #define WX_STRING_TO_X_TYPE_END                                             \
-    /* return true only if scan was stopped by the terminating NUL and */   \
-    /* if the string was not empty to start with and no under/overflow */   \
-    /* occurred: */                                                         \
-    if ( *end || end == start DO_IF_NOT_WINCE(|| errno == ERANGE) )         \
+    if ( end == start DO_IF_NOT_WINCE(|| errno == ERANGE) )                 \
         return false;                                                       \
     *pVal = val;                                                            \
-    return true;
+    return !*end;
 
 bool wxString::ToLong(long *pVal, int base) const
 {