]>
Commit | Line | Data |
---|---|---|
c9f78968 VS |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: src/common/strvararg.cpp | |
3 | // Purpose: macros for implementing type-safe vararg passing of strings | |
4 | // Author: Vaclav Slavik | |
5 | // Created: 2007-02-19 | |
6 | // RCS-ID: $Id$ | |
7 | // Copyright: (c) 2007 REA Elektronik GmbH | |
8 | // Licence: wxWindows licence | |
9 | /////////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | // ============================================================================ | |
12 | // declarations | |
13 | // ============================================================================ | |
14 | ||
15 | // ---------------------------------------------------------------------------- | |
16 | // headers | |
17 | // ---------------------------------------------------------------------------- | |
18 | ||
19 | // for compilers that support precompilation, includes "wx.h". | |
20 | #include "wx/wxprec.h" | |
21 | ||
22 | #ifdef __BORLANDC__ | |
23 | #pragma hdrstop | |
24 | #endif | |
25 | ||
26 | #include "wx/strvararg.h" | |
c9f78968 VS |
27 | #include "wx/string.h" |
28 | ||
29 | // ============================================================================ | |
30 | // implementation | |
31 | // ============================================================================ | |
32 | ||
1528e0b8 VS |
33 | // ---------------------------------------------------------------------------- |
34 | // wxArgNormalizer<> | |
35 | // ---------------------------------------------------------------------------- | |
c9f78968 | 36 | |
2523e9b7 | 37 | const wxStringCharType *wxArgNormalizerNative<const wxString&>::get() const |
c9f78968 | 38 | { |
8f93a29f | 39 | return m_value.wx_str(); |
c9f78968 | 40 | } |
c9f78968 | 41 | |
2523e9b7 | 42 | const wxStringCharType *wxArgNormalizerNative<const wxCStrData&>::get() const |
c9f78968 | 43 | { |
2523e9b7 | 44 | return m_value.AsInternal(); |
c9f78968 VS |
45 | } |
46 | ||
111d9948 | 47 | #if wxUSE_UNICODE_UTF8 && !wxUSE_UTF8_LOCALE_ONLY |
2523e9b7 VS |
48 | wxArgNormalizerWchar<const wxString&>::wxArgNormalizerWchar(const wxString& s) |
49 | : wxArgNormalizerWithBuffer<wchar_t>(s.wc_str()) | |
c9f78968 | 50 | { |
c9f78968 VS |
51 | } |
52 | ||
2523e9b7 VS |
53 | wxArgNormalizerWchar<const wxCStrData&>::wxArgNormalizerWchar(const wxCStrData& s) |
54 | : wxArgNormalizerWithBuffer<wchar_t>(s.AsWCharBuf()) | |
c9f78968 | 55 | { |
81727065 | 56 | } |
111d9948 | 57 | #endif // wxUSE_UNICODE_UTF8 && !wxUSE_UTF8_LOCALE_ONLY |
81727065 | 58 | |
1528e0b8 VS |
59 | // ---------------------------------------------------------------------------- |
60 | // wxArgNormalizedString | |
61 | // ---------------------------------------------------------------------------- | |
62 | ||
2523e9b7 | 63 | wxString wxArgNormalizedString::GetString() const |
359bd4d1 | 64 | { |
2523e9b7 VS |
65 | if ( !IsValid() ) |
66 | return wxEmptyString; | |
67 | ||
68 | #if wxUSE_UTF8_LOCALE_ONLY | |
69 | return wxString(wx_reinterpret_cast(const char*, m_ptr)); | |
70 | #else | |
71 | #if wxUSE_UNICODE_UTF8 | |
72 | if ( wxLocaleIsUtf8 ) | |
73 | return wxString(wx_reinterpret_cast(const char*, m_ptr)); | |
74 | else | |
75 | #endif | |
075ff410 | 76 | return wxString(wx_reinterpret_cast(const wxChar*, m_ptr)); |
2523e9b7 | 77 | #endif // !wxUSE_UTF8_LOCALE_ONLY |
359bd4d1 VS |
78 | } |
79 | ||
2523e9b7 | 80 | wxArgNormalizedString::operator wxString() const |
359bd4d1 | 81 | { |
2523e9b7 | 82 | return GetString(); |
359bd4d1 | 83 | } |
1528e0b8 VS |
84 | |
85 | // ---------------------------------------------------------------------------- | |
86 | // wxFormatString | |
87 | // ---------------------------------------------------------------------------- | |
88 | ||
89 | #if !wxUSE_UNICODE_WCHAR | |
90 | const char* wxFormatString::AsChar() | |
91 | { | |
92 | if ( m_char ) | |
93 | return m_char.data(); | |
94 | ||
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: | |
98 | if ( m_str ) | |
99 | return m_str->wx_str(); | |
100 | ||
101 | // ditto wxCStrData: | |
102 | if ( m_cstr ) | |
103 | return m_cstr->AsInternal(); | |
104 | ||
105 | // the last case is that wide string was passed in: in that case, we need | |
106 | // to convert it: | |
107 | wxASSERT( m_wchar ); | |
108 | ||
109 | m_char = wxConvLibc.cWC2MB(m_wchar.data()); | |
110 | ||
111 | return m_char.data(); | |
112 | } | |
113 | #endif // !wxUSE_UNICODE_WCHAR | |
114 | ||
115 | #if wxUSE_UNICODE && !wxUSE_UTF8_LOCALE_ONLY | |
116 | const wchar_t* wxFormatString::AsWChar() | |
117 | { | |
118 | if ( m_wchar ) | |
119 | return m_wchar.data(); | |
120 | ||
121 | #if wxUSE_UNICODE_WCHAR | |
122 | if ( m_str ) | |
123 | return m_str->wc_str(); | |
124 | if ( m_cstr ) | |
125 | return m_cstr->AsInternal(); | |
126 | #else // wxUSE_UNICODE_UTF8 | |
127 | if ( m_str ) | |
128 | { | |
129 | m_wchar = m_str->wc_str(); | |
130 | return m_wchar.data(); | |
131 | } | |
132 | if ( m_cstr ) | |
133 | { | |
134 | m_wchar = m_cstr->AsWCharBuf(); | |
135 | return m_wchar.data(); | |
136 | } | |
137 | #endif // wxUSE_UNICODE_WCHAR/UTF8 | |
138 | ||
139 | // the last case is that narrow string was passed in: in that case, we need | |
140 | // to convert it: | |
141 | wxASSERT( m_char ); | |
142 | ||
143 | m_wchar = wxConvLibc.cMB2WC(m_char.data()); | |
144 | ||
145 | return m_wchar.data(); | |
146 | } | |
147 | #endif // wxUSE_UNICODE && !wxUSE_UTF8_LOCALE_ONLY |