]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/string.cpp
wxObjArray fix (part 2)
[wxWidgets.git] / src / common / string.cpp
index 749a952b349fc86d1800d7e0ec6c0a4c95983096..e00c8180332fec29d9a58bf666b4290d8722a063 100644 (file)
@@ -106,8 +106,10 @@ extern const char *g_szNul = &g_strEmpty.dummy;
     // always available), but it's unsafe because it doesn't check for buffer
     // size - so give a warning
     #define wxVsprintf(buffer,len,format,argptr) vsprintf(buffer,format, argptr)
+#ifndef __SC__
     #pragma message("Using sprintf() because no snprintf()-like function defined")
 #endif
+#endif
 
 // ----------------------------------------------------------------------------
 // global functions
@@ -345,6 +347,10 @@ void wxString::AllocBeforeWrite(size_t nLen)
     pData->Unlock();
     AllocBuffer(nLen);
   }
+  else {
+    // update the string length
+    pData->nDataLength = nLen;
+  }
 
   wxASSERT( !GetStringData()->IsShared() );  // we must be the only owner
 }
@@ -899,8 +905,13 @@ wxString& wxString::Pad(size_t nCount, char chPad, bool bFromRight)
 // truncate the string
 wxString& wxString::Truncate(size_t uiLen)
 {
-  *(m_pchData + uiLen) = '\0';
-  GetStringData()->nDataLength = uiLen;
+  if ( uiLen < Len() ) {
+    CopyBeforeWrite();
+
+    *(m_pchData + uiLen) = '\0';
+    GetStringData()->nDataLength = uiLen;
+  }
+  //else: nothing to do, string is already short enough
 
   return *this;
 }
@@ -1070,6 +1081,19 @@ bool wxString::Matches(const char *pszMask) const
   return *pszTxt == '\0';
 }
 
+// Count the number of chars
+int wxString::Freq(char ch) const
+{
+    int count = 0;
+    int len = Len();
+    for (int i = 0; i < len; i++)
+    {
+        if (GetChar(i) == ch)
+            count ++;
+    }
+    return count;
+}
+
 // ---------------------------------------------------------------------------
 // standard C++ library string functions
 // ---------------------------------------------------------------------------
@@ -1111,6 +1135,8 @@ size_t wxString::find(const char* sz, size_t nStart, size_t n) const
 }
 #endif
 
+// Gives a duplicate symbol (presumably a case-insensitivity problem)
+#if !defined(__BORLANDC__)
 size_t wxString::find(char ch, size_t nStart) const
 {
   wxASSERT( nStart <= Len() );
@@ -1119,6 +1145,7 @@ size_t wxString::find(char ch, size_t nStart) const
 
   return p == NULL ? npos : p - c_str();
 }
+#endif
 
 size_t wxString::rfind(const wxString& str, size_t nStart) const
 {