]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/string.cpp
wxOS2 with Open Watcom: correct PCH usage, missing headers, warning fixes, source...
[wxWidgets.git] / src / common / string.cpp
index 17c9019e5eb19c4ea74654b5b3ebe9fe2dda364b..cded294536c5f1222b30fad00b24022e6a628e19 100644 (file)
@@ -1397,32 +1397,33 @@ const wxCharBuffer wxString::ToAscii() const
 // extract string of length nCount starting at nFirst
 wxString wxString::Mid(size_t nFirst, size_t nCount) const
 {
-  size_t nLen = length();
+    size_t nLen = length();
 
-  // default value of nCount is npos and means "till the end"
-  if ( nCount == npos )
-  {
-    nCount = nLen - nFirst;
-  }
+    // default value of nCount is npos and means "till the end"
+    if ( nCount == npos )
+    {
+        nCount = nLen - nFirst;
+    }
 
-  // out-of-bounds requests return sensible things
-  if ( nFirst + nCount > nLen )
-  {
-    nCount = nLen - nFirst;
-  }
+    // out-of-bounds requests return sensible things
+    if ( nFirst + nCount > nLen )
+    {
+        nCount = nLen - nFirst;
+    }
 
-  if ( nFirst > nLen )
-  {
-    // AllocCopy() will return empty string
-    nCount = 0;
-  }
+    if ( nFirst > nLen )
+    {
+        // AllocCopy() will return empty string
+        return wxEmptyString;
+    }
 
-  wxString dest(*this, nFirst, nCount);
-  if ( dest.length() != nCount ) {
-      wxFAIL_MSG( _T("out of memory in wxString::Mid") );
-  }
+    wxString dest(*this, nFirst, nCount);
+    if ( dest.length() != nCount )
+    {
+        wxFAIL_MSG( _T("out of memory in wxString::Mid") );
+    }
 
-  return dest;
+    return dest;
 }
 
 // check that the string starts with prefix and return the rest of the string
@@ -1839,24 +1840,22 @@ int wxString::PrintfV(const wxChar* pszFormat, va_list argptr)
         // vsnprintf() may return either -1 (traditional Unix behaviour) or the
         // total number of characters which would have been written if the
         // buffer were large enough
-        // also, it may return an errno may be something like EILSEQ,
-        // in which case we need to break out
-        if ( (len >= 0 && len <= size)
-        // No EOVERFLOW on Windows nor Palm 6.0 nor OpenVMS nor MacOS (not X)
-        // not OS/2 (not Innotek libc).
-#if !defined(__WXMSW__)                              && \
-    !defined(__WXPALMOS__)                           && \
-    !defined( __VMS )                                && \
-    !(defined(__WXMAC__) && !defined(__WXMAC_OSX__)) && \
-    !(defined(__EMX__) && !defined(__INNOTEK_LIBC__))
-            || errno != EOVERFLOW
-#endif
-            )
+        if ( len >= 0 && len <= size )
         {
             // ok, there was enough space
             break;
         }
 
+#ifdef EOVERFLOW
+        // if the error is not due to not having enough space (it could be e.g.
+        // EILSEQ), break too -- we'd just eat all available memory uselessly
+        if ( errno != EOVERFLOW )
+        {
+            // no sense in continuing
+            break;
+        }
+#endif // EOVERFLOW
+
         // still not enough, double it again
         size *= 2;
     }