X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c9f7896861f734ce044ee8601ba2d8a6959c9d9e..696a18c7e7448f195171d0a50a1e4afe231b177d:/src/common/strvararg.cpp diff --git a/src/common/strvararg.cpp b/src/common/strvararg.cpp index e3435e6713..36b6af060b 100644 --- a/src/common/strvararg.cpp +++ b/src/common/strvararg.cpp @@ -24,56 +24,124 @@ #endif #include "wx/strvararg.h" -#include "wx/buffer.h" -#include "wx/strconv.h" #include "wx/string.h" // ============================================================================ // implementation // ============================================================================ -const wxArgNativeCharType *wxArgNormalizer::get() const -{ - return m_value; -} +// ---------------------------------------------------------------------------- +// wxArgNormalizer<> +// ---------------------------------------------------------------------------- -const wxArgNativeCharType *wxArgNormalizer::get() const +const wxStringCharType *wxArgNormalizerNative::get() const { - return m_value.c_str(); + return m_value.wx_str(); } -#if wxUSE_UNICODE_WCHAR - -wxArgNormalizer::wxArgNormalizer(const char *value) +const wxStringCharType *wxArgNormalizerNative::get() const { - m_value = new wxWCharBuffer(wxConvLibc.cMB2WC(value)); + return m_value.AsInternal(); } -wxArgNormalizer::~wxArgNormalizer() +#if wxUSE_UNICODE_UTF8 && !wxUSE_UTF8_LOCALE_ONLY +wxArgNormalizerWchar::wxArgNormalizerWchar(const wxString& s) + : wxArgNormalizerWithBuffer(s.wc_str()) { - delete m_value; } -const wchar_t *wxArgNormalizer::get() const +wxArgNormalizerWchar::wxArgNormalizerWchar(const wxCStrData& s) + : wxArgNormalizerWithBuffer(s.AsWCharBuf()) { - return m_value->data(); } +#endif // wxUSE_UNICODE_UTF8 && !wxUSE_UTF8_LOCALE_ONLY -#elif wxUSE_WCHAR_T // !wxUSE_UNICODE_WCHAR && wxUSE_WCHAR_T +// ---------------------------------------------------------------------------- +// wxArgNormalizedString +// ---------------------------------------------------------------------------- -wxArgNormalizer::wxArgNormalizer(const wchar_t *value) +wxString wxArgNormalizedString::GetString() const { - m_value = new wxCharBuffer(wxConvLibc.cWC2MB(value)); + if ( !IsValid() ) + return wxEmptyString; + +#if wxUSE_UTF8_LOCALE_ONLY + return wxString(wx_reinterpret_cast(const char*, m_ptr)); +#else + #if wxUSE_UNICODE_UTF8 + if ( wxLocaleIsUtf8 ) + return wxString(wx_reinterpret_cast(const char*, m_ptr)); + else + #endif + return wxString(wx_reinterpret_cast(const wxChar*, m_ptr)); +#endif // !wxUSE_UTF8_LOCALE_ONLY } -wxArgNormalizer::~wxArgNormalizer() +wxArgNormalizedString::operator wxString() const { - delete m_value; + return GetString(); } -const char *wxArgNormalizer::get() const +// ---------------------------------------------------------------------------- +// wxFormatString +// ---------------------------------------------------------------------------- + +#if !wxUSE_UNICODE_WCHAR +const char* wxFormatString::AsChar() { - return m_value->data(); + if ( m_char ) + return m_char.data(); + + // in ANSI build, wx_str() returns char*, in UTF-8 build, this function + // is only called under UTF-8 locales, so we should return UTF-8 string, + // which is, again, what wx_str() returns: + if ( m_str ) + return m_str->wx_str(); + + // ditto wxCStrData: + if ( m_cstr ) + return m_cstr->AsInternal(); + + // the last case is that wide string was passed in: in that case, we need + // to convert it: + wxASSERT( m_wchar ); + + m_char = wxConvLibc.cWC2MB(m_wchar.data()); + + return m_char.data(); } +#endif // !wxUSE_UNICODE_WCHAR + +#if wxUSE_UNICODE && !wxUSE_UTF8_LOCALE_ONLY +const wchar_t* wxFormatString::AsWChar() +{ + if ( m_wchar ) + return m_wchar.data(); -#endif // wxUSE_UNICODE_WCHAR / !wxUSE_UNICODE_WCHAR && wxUSE_WCHAR_T +#if wxUSE_UNICODE_WCHAR + if ( m_str ) + return m_str->wc_str(); + if ( m_cstr ) + return m_cstr->AsInternal(); +#else // wxUSE_UNICODE_UTF8 + if ( m_str ) + { + m_wchar = m_str->wc_str(); + return m_wchar.data(); + } + if ( m_cstr ) + { + m_wchar = m_cstr->AsWCharBuf(); + return m_wchar.data(); + } +#endif // wxUSE_UNICODE_WCHAR/UTF8 + + // the last case is that narrow string was passed in: in that case, we need + // to convert it: + wxASSERT( m_char ); + + m_wchar = wxConvLibc.cMB2WC(m_char.data()); + + return m_wchar.data(); +} +#endif // wxUSE_UNICODE && !wxUSE_UTF8_LOCALE_ONLY