wxString(const wxString& str, size_t nLength)
: m_impl(str.Mid(0, nLength).m_impl) {}
- ~wxString();
-
public:
// standard types
typedef wxUniChar value_type;
private:
wxStringImpl m_impl;
+
+ // buffers for compatibility conversion from (char*)c_str() and
+ // (wchar_t*)c_str():
+ // FIXME-UTF8: bechmark various approaches to keeping compatibility buffers
+ template<typename T>
+ struct ConvertedBuffer
+ {
+ ConvertedBuffer() : m_buf(NULL) {}
+ ~ConvertedBuffer()
+ { free(m_buf); }
+
+ operator const T*() const { return m_buf; }
+
+ ConvertedBuffer& operator=(T *str)
+ {
+ free(m_buf);
+ m_buf = str;
+ return *this;
+ }
+
+ T *m_buf;
+ };
+#if wxUSE_UNICODE
+ ConvertedBuffer<char> m_convertedToChar;
+#endif
+#if !wxUSE_UNICODE_WCHAR
+ ConvertedBuffer<wchar_t> m_convertedToWChar;
+#endif
+ friend class WXDLLIMPEXP_BASE wxCStrData;
};
#ifdef wxNEEDS_WXSTRING_PRINTF_MIXIN
// wxCStrData converted strings caching
// ----------------------------------------------------------------------------
+// FIXME-UTF8: temporarily disabled because it doesn't work with global
+// string objects; re-enable after fixing this bug and benchmarking
+// performance to see if using a hash is a good idea at all
+#if 0
+
// For backward compatibility reasons, it must be possible to assign the value
// returned by wxString::c_str() to a char* or wchar_t* variable and work with
// it. Returning wxCharBuffer from (const char*)c_str() wouldn't do the trick,
}
#endif // !wxUSE_UNICODE_WCHAR
-// ===========================================================================
-// wxString class core
-// ===========================================================================
-
-// ---------------------------------------------------------------------------
-// construction and conversion
-// ---------------------------------------------------------------------------
-
wxString::~wxString()
{
#if wxUSE_UNICODE
DeleteStringFromConversionCache(gs_stringsWCharCache, this);
#endif
}
+#endif
+
+#if wxUSE_UNICODE
+const char* wxCStrData::AsChar() const
+{
+ wxString *str = wxConstCast(m_str, wxString);
+ // convert the string and keep it:
+ str->m_convertedToChar = str->mb_str().release();
+ return str->m_convertedToChar + m_offset;
+}
+#endif // wxUSE_UNICODE
+
+#if !wxUSE_UNICODE_WCHAR
+const wchar_t* wxCStrData::AsWChar() const
+{
+ wxString *str = wxConstCast(m_str, wxString);
+ // convert the string and keep it:
+ str->m_convertedToWChar = str->wc_str().release();
+ return str->m_convertedToWChar + m_offset;
+}
+#endif // !wxUSE_UNICODE_WCHAR
+
+// ===========================================================================
+// wxString class core
+// ===========================================================================
+
+// ---------------------------------------------------------------------------
+// construction and conversion
+// ---------------------------------------------------------------------------
#if wxUSE_UNICODE
/* static */