]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/string.cpp
rename old wxAppConsole to wxAppConsoleBase and wxAppConsoleUnix to wxAppConsole...
[wxWidgets.git] / src / common / string.cpp
index dac95cc926ead09641f74274df6d2c882317609a..34453a87c3d8df365c1c90b476c75375e5e7be3b 100644 (file)
@@ -340,7 +340,7 @@ wxString::SubstrBufFromMB wxString::ConvertStr(const char *psz, size_t nLength,
         return SubstrBufFromMB("", 0);
 
     // and then to UTF-8:
-    SubstrBufFromMB buf(ConvertStr(wcBuf, wcLen, wxConvUTF8));
+    SubstrBufFromMB buf(ConvertStr(wcBuf, wcLen, wxMBConvUTF8()));
     // widechar -> UTF-8 conversion isn't supposed to ever fail:
     wxASSERT_MSG( buf.data, _T("conversion to UTF-8 failed") );
 
@@ -382,9 +382,9 @@ const wxCharBuffer wxString::mb_str(const wxMBConv& conv) const
 
 const wxWCharBuffer wxString::wc_str() const
 {
-    return wxConvUTF8.cMB2WC(m_impl.c_str(),
-                             m_impl.length() + 1 /* size, not length */,
-                             NULL);
+    return wxMBConvUTF8().cMB2WC(m_impl.c_str(),
+                                 m_impl.length() + 1 /* size, not length */,
+                                 NULL);
 }
 
 const wxCharBuffer wxString::mb_str(const wxMBConv& conv) const
@@ -396,9 +396,9 @@ const wxCharBuffer wxString::mb_str(const wxMBConv& conv) const
 
     size_t wcLen;
     wxWCharBuffer wcBuf(
-            wxConvUTF8.cMB2WC(m_impl.c_str(),
-                              m_impl.length() + 1 /* size, not length */,
-                              &wcLen));
+            wxMBConvUTF8().cMB2WC(m_impl.c_str(),
+                                  m_impl.length() + 1 /* size, not length */,
+                                  &wcLen));
     if ( !wcLen )
         return wxCharBuffer("");
 
@@ -1065,28 +1065,15 @@ wxString wxString::Mid(size_t nFirst, size_t nCount) const
 
 // check that the string starts with prefix and return the rest of the string
 // in the provided pointer if it is not NULL, otherwise return false
-bool wxString::StartsWith(const wxChar *prefix, wxString *rest) const
+bool wxString::StartsWith(const wxString& prefix, wxString *rest) const
 {
-    wxASSERT_MSG( prefix, _T("invalid parameter in wxString::StartsWith") );
-
-    // first check if the beginning of the string matches the prefix: note
-    // that we don't have to check that we don't run out of this string as
-    // when we reach the terminating NUL, either prefix string ends too (and
-    // then it's ok) or we break out of the loop because there is no match
-    const wxChar *p = c_str();
-    while ( *prefix )
-    {
-        if ( *prefix++ != *p++ )
-        {
-            // no match
-            return false;
-        }
-    }
+    if ( compare(0, prefix.length(), prefix) != 0 )
+        return false;
 
     if ( rest )
     {
         // put the rest of the string into provided pointer
-        *rest = p;
+        rest->assign(*this, prefix.length(), npos);
     }
 
     return true;
@@ -1095,11 +1082,9 @@ bool wxString::StartsWith(const wxChar *prefix, wxString *rest) const
 
 // check that the string ends with suffix and return the rest of it in the
 // provided pointer if it is not NULL, otherwise return false
-bool wxString::EndsWith(const wxChar *suffix, wxString *rest) const
+bool wxString::EndsWith(const wxString& suffix, wxString *rest) const
 {
-    wxASSERT_MSG( suffix, _T("invalid parameter in wxString::EndssWith") );
-
-    int start = length() - wxStrlen(suffix);
+    int start = length() - suffix.length();
 
     if ( start < 0 || compare(start, npos, suffix) != 0 )
         return false;
@@ -1632,9 +1617,6 @@ static int DoStringPrintfV(wxString& str,
 
 int wxString::PrintfV(const wxString& format, va_list argptr)
 {
-    va_list argcopy;
-    wxVaCopy(argcopy, argptr);
-
 #if wxUSE_UNICODE_UTF8
     #if wxUSE_STL_BASED_WXSTRING
         typedef wxStringTypeBuffer<char> Utf8Buffer;
@@ -1644,16 +1626,16 @@ int wxString::PrintfV(const wxString& format, va_list argptr)
 #endif
 
 #if wxUSE_UTF8_LOCALE_ONLY
-    return DoStringPrintfV<Utf8Buffer>(*this, format, argcopy);
+    return DoStringPrintfV<Utf8Buffer>(*this, format, argptr);
 #else
     #if wxUSE_UNICODE_UTF8
     if ( wxLocaleIsUtf8 )
-        return DoStringPrintfV<Utf8Buffer>(*this, format, argcopy);
+        return DoStringPrintfV<Utf8Buffer>(*this, format, argptr);
     else
         // wxChar* version
-        return DoStringPrintfV<wxStringBuffer>(*this, format, argcopy);
+        return DoStringPrintfV<wxStringBuffer>(*this, format, argptr);
     #else
-        return DoStringPrintfV(*this, format, argcopy);
+        return DoStringPrintfV(*this, format, argptr);
     #endif // UTF8/WCHAR
 #endif
 }