]> git.saurik.com Git - wxWidgets.git/commitdiff
wxString::Truncates() now doesn't change the sharied copies of the string
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 17 Dec 1998 20:23:13 +0000 (20:23 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 17 Dec 1998 20:23:13 +0000 (20:23 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1226 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/string.cpp

index 749a952b349fc86d1800d7e0ec6c0a4c95983096..77026933c0abc56f22083cd9bd768ebad0d80d8e 100644 (file)
@@ -899,8 +899,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;
 }