X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5c33522fca7cddc441a316f5b9fb50d7685435ba..dbe0872fc80f7fc9ac37235ab1f8ba8224b0bfa5:/src/common/strvararg.cpp?ds=sidebyside diff --git a/src/common/strvararg.cpp b/src/common/strvararg.cpp index b06f3e6cf2..e71c060b10 100644 --- a/src/common/strvararg.cpp +++ b/src/common/strvararg.cpp @@ -152,7 +152,7 @@ public: m_nCopied = 0; } - wxCharTypeBuffer Convert(const CharType *format) + wxScopedCharTypeBuffer Convert(const CharType *format) { // this is reset to NULL if we modify the format string m_fmtOrig = format; @@ -263,12 +263,14 @@ public: // format if ( m_fmtOrig ) { - return wxCharTypeBuffer::CreateNonOwned(m_fmtOrig); + return wxScopedCharTypeBuffer::CreateNonOwned(m_fmtOrig); } else { - // NULL-terminate converted format string: - *m_fmtLast = 0; + // shrink converted format string to actual size (instead of + // over-sized allocation from CopyAllBefore()) and NUL-terminate + // it: + m_fmt.shrink(m_fmtLast - m_fmt.data()); return m_fmt; } } @@ -373,9 +375,7 @@ private: size_t m_nCopied; }; - - -#ifdef __WINDOWS +#ifdef __WINDOWS__ // on Windows, we should use %s and %c regardless of the build: class wxPrintfFormatConverterWchar : public wxFormatConverterBase @@ -520,7 +520,7 @@ class wxScanfFormatConverterWchar : public wxFormatConverterBase } }; -const wxWCharBuffer wxScanfConvertFormatW(const wchar_t *format) +const wxScopedWCharBuffer wxScanfConvertFormatW(const wchar_t *format) { return wxScanfFormatConverterWchar().Convert(format); } @@ -611,6 +611,21 @@ const wchar_t* wxFormatString::AsWChar() } #endif // wxUSE_UNICODE && !wxUSE_UTF8_LOCALE_ONLY +wxString wxFormatString::InputAsString() const +{ + if ( m_str ) + return *m_str; + if ( m_cstr ) + return m_cstr->AsString(); + if ( m_wchar ) + return wxString(m_wchar); + if ( m_char ) + return wxString(m_char); + + wxFAIL_MSG( "invalid wxFormatString - not initialized?" ); + return wxString(); +} + // ---------------------------------------------------------------------------- // wxFormatString::GetArgumentType() // ----------------------------------------------------------------------------