]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/string.cpp
wxUSE_XXX related fixes
[wxWidgets.git] / src / common / string.cpp
index 6b21ca1b09588be2a81743b63c5c93ffc86c5c07..6ddd68f0c7cfb69441da9a37452ca44fb5268189 100644 (file)
@@ -326,7 +326,7 @@ wxStringBase& wxStringBase::append(size_t n, wxChar ch)
 {
     size_type len = length();
 
 {
     size_type len = length();
 
-    if ( !CopyBeforeWrite() || !Alloc(len + n) ) {
+    if ( !Alloc(len + n) || !CopyBeforeWrite() ) {
       wxFAIL_MSG( _T("out of memory in wxStringBase::append") );
     }
     GetStringData()->nDataLength = len + n;
       wxFAIL_MSG( _T("out of memory in wxStringBase::append") );
     }
     GetStringData()->nDataLength = len + n;
@@ -380,7 +380,9 @@ bool wxStringBase::Alloc(size_t nLen)
         // allocation failure handled by caller
         return false;
       }
         // allocation failure handled by caller
         return false;
       }
-      memcpy(m_pchData, pData->data(), nOldLen*sizeof(wxChar));
+      // +1 to copy the terminator, too
+      memcpy(m_pchData, pData->data(), (nOldLen+1)*sizeof(wxChar));
+      GetStringData()->nDataLength = nOldLen;
     }
     else {
       nLen += EXTRA_ALLOC;
     }
     else {
       nLen += EXTRA_ALLOC;
@@ -445,7 +447,7 @@ wxStringBase& wxStringBase::insert(size_t nPos, const wxChar *sz, size_t n)
   if ( n == npos ) n = wxStrlen(sz);
   if ( n == 0 ) return *this;
 
   if ( n == npos ) n = wxStrlen(sz);
   if ( n == 0 ) return *this;
 
-  if ( !CopyBeforeWrite() || !Alloc(length() + n) ) {
+  if ( !Alloc(length() + n) || !CopyBeforeWrite() ) {
     wxFAIL_MSG( _T("out of memory in wxStringBase::insert") );
   }
 
     wxFAIL_MSG( _T("out of memory in wxStringBase::insert") );
   }
 
@@ -481,8 +483,14 @@ size_t wxStringBase::find(const wxStringBase& str, size_t nStart) const
   while(p - c_str() + str.length() <= length() &&
         wxTmemcmp(p, str.c_str(), str.length()) )
   {
   while(p - c_str() + str.length() <= length() &&
         wxTmemcmp(p, str.c_str(), str.length()) )
   {
+      //Previosly passed as the first argument to wxTmemchr,
+      //but C/C++ standard does not specify evaluation order
+      //of arguments to functions -
+      //http://embedded.com/showArticle.jhtml?articleID=9900607
+      ++p;
+
       //anchor again
       //anchor again
-      p = (const wxChar*)wxTmemchr(++p,
+      p = (const wxChar*)wxTmemchr(p,
                                   str.c_str()[0],
                                   length() - (p - c_str()));
 
                                   str.c_str()[0],
                                   length() - (p - c_str()));
 
@@ -1024,7 +1032,7 @@ wxString::wxString(const char *psz, wxMBConv& conv, size_t nLength)
         size_t nRealSize;
         wxWCharBuffer theBuffer = conv.cMB2WC(psz, nLen, &nRealSize);
 
         size_t nRealSize;
         wxWCharBuffer theBuffer = conv.cMB2WC(psz, nLen, &nRealSize);
 
-        //Copy 
+        //Copy
         if (nRealSize)
             assign( theBuffer.data() , nRealSize - 1 );
     }
         if (nRealSize)
             assign( theBuffer.data() , nRealSize - 1 );
     }
@@ -1080,7 +1088,7 @@ wxString::wxString(const wchar_t *pwz, wxMBConv& conv, size_t nLength)
         size_t nRealSize;
         wxCharBuffer theBuffer = conv.cWC2MB(pwz, nLen, &nRealSize);
 
         size_t nRealSize;
         wxCharBuffer theBuffer = conv.cWC2MB(pwz, nLen, &nRealSize);
 
-        //Copy 
+        //Copy
         if (nRealSize)
             assign( theBuffer.data() , nRealSize - 1 );
     }
         if (nRealSize)
             assign( theBuffer.data() , nRealSize - 1 );
     }
@@ -1219,7 +1227,7 @@ wxString operator+(const wxString& str, const wxChar *psz)
   if ( !s.Alloc(wxStrlen(psz) + str.Len()) ) {
     wxFAIL_MSG( _T("out of memory in wxString::operator+") );
   }
   if ( !s.Alloc(wxStrlen(psz) + str.Len()) ) {
     wxFAIL_MSG( _T("out of memory in wxString::operator+") );
   }
-  s = str;
+  s += str;
   s += psz;
 
   return s;
   s += psz;
 
   return s;
@@ -1629,7 +1637,7 @@ inline int wxSafeIsspace(wxChar ch) { return (ch < 127) && wxIsspace(ch); }
 wxString& wxString::Trim(bool bFromRight)
 {
   // first check if we're going to modify the string at all
 wxString& wxString::Trim(bool bFromRight)
 {
   // first check if we're going to modify the string at all
-  if ( !IsEmpty() &&
+  if ( !empty() &&
        (
         (bFromRight && wxSafeIsspace(GetChar(Len() - 1))) ||
         (!bFromRight && wxSafeIsspace(GetChar(0u)))
        (
         (bFromRight && wxSafeIsspace(GetChar(Len() - 1))) ||
         (!bFromRight && wxSafeIsspace(GetChar(0u)))
@@ -2195,6 +2203,11 @@ wxString* wxArrayString::GetStringArray() const
     return array;
 }
 
     return array;
 }
 
+void wxArrayString::Remove(size_t nIndex, size_t nRemove)
+{
+    RemoveAt(nIndex, nRemove);
+}
+
 #endif // WXWIN_COMPATIBILITY_2_4
 
 // searches the array for an item (forward or backwards)
 #endif // WXWIN_COMPATIBILITY_2_4
 
 // searches the array for an item (forward or backwards)