const wchar_t* AsWChar() const;
operator const wchar_t*() const { return AsWChar(); }
-#if !wxUSE_UNICODE
+#if !wxUSE_UNICODE || wxUSE_UTF8_LOCALE_ONLY
inline
#endif
const char* AsChar() const;
// static wxString Format(const wString& format, ...) ATTRIBUTE_PRINTF_1;
WX_DEFINE_VARARG_FUNC_SANS_N0(static typename StringReturnType<T1>::type,
- Format, 1, (const wxString&),
+ Format, 1, (const wxFormatString&),
DoFormatWchar, DoFormatUtf8)
// We have to implement the version without template arguments manually
// because of the StringReturnType<> hack, although WX_DEFINE_VARARG_FUNC
template<typename T>
inline static typename StringReturnType<T>::type
- Format(const wxString& fmt, FormatDummyArg dummy = FormatDummyArg())
+ Format(const wxFormatString& fmt, FormatDummyArg dummy = FormatDummyArg())
{
- return DoFormat(fmt);
+ return DoFormatWchar(fmt);
}
// int Printf(const wxString& format, ...);
- WX_DEFINE_VARARG_FUNC(int, Printf, 1, (const wxString&),
+ WX_DEFINE_VARARG_FUNC(int, Printf, 1, (const wxFormatString&),
DoPrintfWchar, DoPrintfUtf8)
// int sprintf(const wxString& format, ...) ATTRIBUTE_PRINTF_2;
- WX_DEFINE_VARARG_FUNC(int, sprintf, 1, (const wxString&),
+ WX_DEFINE_VARARG_FUNC(int, sprintf, 1, (const wxFormatString&),
DoPrintfWchar, DoPrintfUtf8)
protected:
#else // wxUSE_UNICODE_UTF8
- // FIXME-UTF8: return as-is without copying under UTF8 locale, return
- // converted string under other locales - needs wxCharBuffer
- // changes
static wxCharBuffer ImplStr(const char* str,
const wxMBConv& conv = wxConvLibc)
{ return ConvertStr(str, npos, conv).data; }
{ return wxStdWideString(wc_str()); }
#endif
- #if !wxUSE_UNICODE && wxUSE_STL_BASED_WXSTRING
- // FIXME-UTF8: do this in UTF8 build #if wxUSE_UTF8_LOCALE_ONLY, too
+ #if (!wxUSE_UNICODE || wxUSE_UTF8_LOCALE_ONLY) && wxUSE_STL_BASED_WXSTRING
// wxStringImpl is std::string in the encoding we want
operator const std::string&() const { return m_impl; }
#else
// FIXME-UTF8: broken for embedded NULs
{ return std::string(mb_str()); }
#endif
-
-#endif // wxUSE_STD_STRING
+#endif // wxUSE_STL
// first valid index position
const_iterator begin() const { return const_iterator(m_impl.begin()); }
const char *ToAscii() const { return c_str(); }
#endif // Unicode/!Unicode
+ // conversion to/from UTF-8:
+#if wxUSE_UNICODE_UTF8
+ static wxString FromUTF8(const char *utf8)
+ {
+ wxASSERT( wxStringOperations::IsValidUtf8String(utf8) );
+ return FromImpl(wxStringImpl(utf8));
+ }
+ static wxString FromUTF8(const char *utf8, size_t len)
+ {
+ wxASSERT( wxStringOperations::IsValidUtf8String(utf8, len) );
+ return FromImpl(wxStringImpl(utf8, len));
+ }
+ const char* utf8_str() const { return wx_str(); }
+ const char* ToUTF8() const { return wx_str(); }
+#elif wxUSE_UNICODE_WCHAR
+ static wxString FromUTF8(const char *utf8)
+ { return wxString(utf8, wxConvUTF8); }
+ static wxString FromUTF8(const char *utf8, size_t len)
+ { return wxString(utf8, wxConvUTF8, len); }
+ const wxCharBuffer utf8_str() const { return mb_str(wxConvUTF8); }
+ const wxCharBuffer ToUTF8() const { return utf8_str(); }
+#else // ANSI
+ static wxString FromUTF8(const char *utf8)
+ { return wxString(wxConvUTF8.cMB2WC(utf8)); }
+ static wxString FromUTF8(const char *utf8, size_t len)
+ { return wxString(wxConvUTF8.cMB2WC(utf8, len == npos ? wxNO_LEN : len)); }
+ const wxCharBuffer utf8_str() const { return wxConvUTF8.cWC2MB(wc_str()); }
+ const wxCharBuffer ToUTF8() const { return utf8_str(); }
+#endif
+
// functions for storing binary data in wxString:
#if wxUSE_UNICODE
static wxString From8BitData(const char *data, size_t len)
// type differs because a function may either return pointer to the buffer
// directly or have to use intermediate buffer for translation.
#if wxUSE_UNICODE
+
+#if wxUSE_UTF8_LOCALE_ONLY
+ const char* mb_str() const { return wx_str(); }
+ const wxCharBuffer mb_str(const wxMBConv& conv) const;
+#else
const wxCharBuffer mb_str(const wxMBConv& conv = wxConvLibc) const;
+#endif
const wxWX2MBbuf mbc_str() const { return mb_str(*wxConvCurrent); }
// as sprintf(), returns the number of characters written or < 0 on error
// (take 'this' into account in attribute parameter count)
// int Printf(const wxString& format, ...);
- WX_DEFINE_VARARG_FUNC(int, Printf, 1, (const wxString&),
+ WX_DEFINE_VARARG_FUNC(int, Printf, 1, (const wxFormatString&),
DoPrintfWchar, DoPrintfUtf8)
#ifdef __WATCOMC__
- WX_DEFINE_VARARG_FUNC(int, Printf, 1, (const char*)
+ WX_DEFINE_VARARG_FUNC(int, Printf, 1, (const char*),
DoPrintfWchar, DoPrintfUtf8)
- WX_DEFINE_VARARG_FUNC(int, Printf, 1, (const wchar_t*)
+ WX_DEFINE_VARARG_FUNC(int, Printf, 1, (const wchar_t*),
DoPrintfWchar, DoPrintfUtf8)
- WX_DEFINE_VARARG_FUNC(int, Printf, 1, (const wxCStrData&)
+ WX_DEFINE_VARARG_FUNC(int, Printf, 1, (const wxCStrData&),
DoPrintfWchar, DoPrintfUtf8)
#endif
#endif // !wxNEEDS_WXSTRING_PRINTF_MIXIN
#ifndef wxNEEDS_WXSTRING_PRINTF_MIXIN
// returns the string containing the result of Printf() to it
// static wxString Format(const wxString& format, ...) ATTRIBUTE_PRINTF_1;
- WX_DEFINE_VARARG_FUNC(static wxString, Format, 1, (const wxString&),
+ WX_DEFINE_VARARG_FUNC(static wxString, Format, 1, (const wxFormatString&),
DoFormatWchar, DoFormatUtf8)
#ifdef __WATCOMC__
// workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
// use Printf()
// (take 'this' into account in attribute parameter count)
// int sprintf(const wxString& format, ...) ATTRIBUTE_PRINTF_2;
- WX_DEFINE_VARARG_FUNC(int, sprintf, 1, (const wxString&),
+ WX_DEFINE_VARARG_FUNC(int, sprintf, 1, (const wxFormatString&),
DoPrintfWchar, DoPrintfUtf8)
#ifdef __WATCOMC__
// workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
T *m_buf;
};
-#if wxUSE_UNICODE
+#if wxUSE_UNICODE && !wxUSE_UTF8_LOCALE_ONLY
ConvertedBuffer<char> m_convertedToChar;
#endif
#if !wxUSE_UNICODE_WCHAR
}
#endif // wxUSE_UNICODE_WCHAR
-#if !wxUSE_UNICODE
+#if !wxUSE_UNICODE || wxUSE_UTF8_LOCALE_ONLY
inline const char* wxCStrData::AsChar() const
{
- return m_str->wx_str() + m_offset;
+ return wxStringOperations::AddToIter(m_str->wx_str(), m_offset);
}
#endif // !wxUSE_UNICODE