]> git.saurik.com Git - wxWidgets.git/commitdiff
fixed wxString::Mid() bug
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 30 Sep 1998 12:41:13 +0000 (12:41 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 30 Sep 1998 12:41:13 +0000 (12:41 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@788 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/string.cpp

index 054074c259f0483fd0208e95d8331bcc033e6b5d..88f44a8a8ea733812af09c03b78b2e167fb55946 100644 (file)
@@ -564,20 +564,32 @@ void wxString::AllocCopy(wxString& dest, int nCopyLen, int nCopyIndex) const
 }
 
 // extract string of length nCount starting at nFirst
-// default value of nCount is 0 and means "till the end"
 wxString wxString::Mid(size_t nFirst, size_t nCount) const
 {
+  wxStringData *pData = GetStringData();
+  size_t nLen = pData->nDataLength;
+
+  // default value of nCount is STRING_MAXLEN and means "till the end"
+  if ( nCount == STRING_MAXLEN )
+  {
+    nCount = nLen - nFirst;
+  }
+
   // out-of-bounds requests return sensible things
-  if ( nCount == 0 )
-    nCount = GetStringData()->nDataLength - nFirst;
+  if ( nFirst + nCount > nLen )
+  {
+    nCount = nLen - nFirst;
+  }
 
-  if ( nFirst + nCount > (size_t)GetStringData()->nDataLength )
-    nCount = GetStringData()->nDataLength - nFirst;
-  if ( nFirst > (size_t)GetStringData()->nDataLength )
+  if ( nFirst > nLen )
+  {
+    // AllocCopy() will return empty string
     nCount = 0;
+  }
 
   wxString dest;
   AllocCopy(dest, nCount, nFirst);
+
   return dest;
 }