1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/strvararg.cpp
3 // Purpose: macros for implementing type-safe vararg passing of strings
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2007 REA Elektronik GmbH
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
26 #include "wx/strvararg.h"
27 #include "wx/string.h"
29 // ============================================================================
31 // ============================================================================
33 // ----------------------------------------------------------------------------
35 // ----------------------------------------------------------------------------
37 const wxStringCharType
*wxArgNormalizerNative
<const wxString
&>::get() const
39 return m_value
.wx_str();
42 const wxStringCharType
*wxArgNormalizerNative
<const wxCStrData
&>::get() const
44 return m_value
.AsInternal();
47 #if wxUSE_UNICODE_UTF8 && !wxUSE_UTF8_LOCALE_ONLY
48 wxArgNormalizerWchar
<const wxString
&>::wxArgNormalizerWchar(const wxString
& s
)
49 : wxArgNormalizerWithBuffer
<wchar_t>(s
.wc_str())
53 wxArgNormalizerWchar
<const wxCStrData
&>::wxArgNormalizerWchar(const wxCStrData
& s
)
54 : wxArgNormalizerWithBuffer
<wchar_t>(s
.AsWCharBuf())
57 #endif // wxUSE_UNICODE_UTF8 && !wxUSE_UTF8_LOCALE_ONLY
59 // ----------------------------------------------------------------------------
60 // wxArgNormalizedString
61 // ----------------------------------------------------------------------------
63 wxString
wxArgNormalizedString::GetString() const
68 #if wxUSE_UTF8_LOCALE_ONLY
69 return wxString(wx_reinterpret_cast(const char*, m_ptr
));
71 #if wxUSE_UNICODE_UTF8
73 return wxString(wx_reinterpret_cast(const char*, m_ptr
));
76 return wxString(wx_reinterpret_cast(const wxChar
*, m_ptr
));
77 #endif // !wxUSE_UTF8_LOCALE_ONLY
80 wxArgNormalizedString::operator wxString() const
85 // ----------------------------------------------------------------------------
87 // ----------------------------------------------------------------------------
89 #if !wxUSE_UNICODE_WCHAR
90 const char* wxFormatString::AsChar()
95 // in ANSI build, wx_str() returns char*, in UTF-8 build, this function
96 // is only called under UTF-8 locales, so we should return UTF-8 string,
97 // which is, again, what wx_str() returns:
99 return m_str
->wx_str();
103 return m_cstr
->AsInternal();
105 // the last case is that wide string was passed in: in that case, we need
109 m_char
= wxConvLibc
.cWC2MB(m_wchar
.data());
111 return m_char
.data();
113 #endif // !wxUSE_UNICODE_WCHAR
115 #if wxUSE_UNICODE && !wxUSE_UTF8_LOCALE_ONLY
116 const wchar_t* wxFormatString::AsWChar()
119 return m_wchar
.data();
121 #if wxUSE_UNICODE_WCHAR
123 return m_str
->wc_str();
125 return m_cstr
->AsInternal();
126 #else // wxUSE_UNICODE_UTF8
129 m_wchar
= m_str
->wc_str();
130 return m_wchar
.data();
134 m_wchar
= m_cstr
->AsWCharBuf();
135 return m_wchar
.data();
137 #endif // wxUSE_UNICODE_WCHAR/UTF8
139 // the last case is that narrow string was passed in: in that case, we need
143 m_wchar
= wxConvLibc
.cMB2WC(m_char
.data());
145 return m_wchar
.data();
147 #endif // wxUSE_UNICODE && !wxUSE_UTF8_LOCALE_ONLY