#endif
#include "wx/strvararg.h"
-#include "wx/buffer.h"
-#include "wx/strconv.h"
#include "wx/string.h"
// ============================================================================
// implementation
// ============================================================================
-const wxChar *wxArgNormalizer<const wxCStrData&>::get() const
-{
- // FIXME-UTF8: use some way that doesn't involve implicit conversion,
- // so that we deallocate any converted buffer immediately;
- // can't use AsString() because it returns wxString and not
- // const wxString&, unfortunately; use As[W]CharBuf() when
- // available.
- return m_value;
-}
+// ----------------------------------------------------------------------------
+// wxArgNormalizer<>
+// ----------------------------------------------------------------------------
-const wxChar *wxArgNormalizer<const wxString&>::get() const
+const wxStringCharType *wxArgNormalizerNative<const wxString&>::get() const
{
-#if wxUSE_UNICODE_UTF8 // FIXME-UTF8
- return (const wxChar*)m_value;
-#else
return m_value.wx_str();
-#endif
}
-#if wxUSE_UNICODE // FIXME-UTF8: should be wxUSE_UNICODE_WCHAR
-wxArgNormalizer<const char*>::wxArgNormalizer(const char *value)
+const wxStringCharType *wxArgNormalizerNative<const wxCStrData&>::get() const
{
- // FIXME-UTF8: move this to the header so that m_value doesn't have
- // to be dynamically allocated
- m_value = new wxWCharBuffer(wxConvLibc.cMB2WC(value));
+ return m_value.AsInternal();
}
-wxArgNormalizer<const char*>::~wxArgNormalizer()
+#if wxUSE_UNICODE_UTF8 && !wxUSE_UTF8_LOCALE_ONLY
+wxArgNormalizerWchar<const wxString&>::wxArgNormalizerWchar(const wxString& s)
+ : wxArgNormalizerWithBuffer<wchar_t>(s.wc_str())
{
- delete m_value;
}
-const wchar_t *wxArgNormalizer<const char*>::get() const
+wxArgNormalizerWchar<const wxCStrData&>::wxArgNormalizerWchar(const wxCStrData& s)
+ : wxArgNormalizerWithBuffer<wchar_t>(s.AsWCharBuf())
{
- return m_value->data();
}
-#endif // wxUSE_UNICODE_WCHAR
+#endif // wxUSE_UNICODE_UTF8 && !wxUSE_UTF8_LOCALE_ONLY
+// ----------------------------------------------------------------------------
+// wxArgNormalizedString
+// ----------------------------------------------------------------------------
-#if /*wxUSE_UNICODE_UTF8 ||*/ !wxUSE_UNICODE // FIXME-UTF8
-wxArgNormalizer<const wchar_t*>::wxArgNormalizer(const wchar_t *value)
+wxString wxArgNormalizedString::GetString() const
{
-#if wxUSE_UNICODE_UTF8 // FIXME-UTF8: this will be the only case
- m_value = new wxCharBuffer(wxConvUTF8.cWC2MB(value));
+ if ( !IsValid() )
+ return wxEmptyString;
+
+#if wxUSE_UTF8_LOCALE_ONLY
+ return wxString(wx_reinterpret_cast(const char*, m_ptr));
#else
- m_value = new wxCharBuffer(wxConvLibc.cWC2MB(value));
-#endif
+ #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<const wchar_t*>::~wxArgNormalizer()
+wxArgNormalizedString::operator wxString() const
{
- delete m_value;
+ return GetString();
}
-const char *wxArgNormalizer<const wchar_t*>::get() const
-{
- return m_value->data();
-}
-#endif // wxUSE_UNICODE_UTF8 || !wxUSE_UNICODE
+// ----------------------------------------------------------------------------
+// wxFormatString
+// ----------------------------------------------------------------------------
-#if 0 // wxUSE_UNICODE_UTF8 - FIXME-UTF8
-wxArgNormalizer<const char*>::wxArgNormalizer(const char *value)
+#if !wxUSE_UNICODE_WCHAR
+const char* wxFormatString::AsChar()
{
- // FIXME-UTF8: move this to the header so that m_value doesn't have
- // to be dynamically allocated
- // FIXME-UTF8: optimize this if current locale is UTF-8 one
+ if ( m_char )
+ return m_char.data();
- // convert to widechar string first:
- wxWCharBuffer buf(wxConvLibc.cMB2WC(value));
+ // 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();
- if ( buf )
- {
- // then to UTF-8:
- m_value = new wxCharBuffer(wxConvUTF8.cWC2MB(value));
- }
- else
- {
- m_value = new wxCharBuffer();
- }
-}
+ // ditto wxCStrData:
+ if ( m_cstr )
+ return m_cstr->AsInternal();
-wxArgNormalizer<const char*>::~wxArgNormalizer()
-{
- delete m_value;
-}
+ // the last case is that wide string was passed in: in that case, we need
+ // to convert it:
+ wxASSERT( m_wchar );
-const char *wxArgNormalizer<const char*>::get() const
-{
- return m_value->data();
+ m_char = wxConvLibc.cWC2MB(m_wchar.data());
+
+ return m_char.data();
}
-#endif // wxUSE_UNICODE_UTF8
+#endif // !wxUSE_UNICODE_WCHAR
+#if wxUSE_UNICODE && !wxUSE_UTF8_LOCALE_ONLY
+const wchar_t* wxFormatString::AsWChar()
+{
+ if ( m_wchar )
+ return m_wchar.data();
+
+#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 );
-// FIXME-UTF8: move this to the header once it's possible to include buffer.h
-// without including wxcrt.h
-wxArgNormalizer<wxCharBuffer>::wxArgNormalizer(const wxCharBuffer& buf)
- : wxArgNormalizer<const char*>(buf.data())
-{
-}
+ m_wchar = wxConvLibc.cMB2WC(m_char.data());
-wxArgNormalizer<wxWCharBuffer>::wxArgNormalizer(const wxWCharBuffer& buf)
- : wxArgNormalizer<const wchar_t*>(buf.data())
-{
+ return m_wchar.data();
}
+#endif // wxUSE_UNICODE && !wxUSE_UTF8_LOCALE_ONLY