cleanup of wxString ctors and operator=: made both char* and wchar_t* versions available, regardless of the build
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45242 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
9859d369b4
commit
04abe4bc8f
@ -483,78 +483,69 @@ public:
|
|||||||
// constructors and destructor
|
// constructors and destructor
|
||||||
// ctor for an empty string
|
// ctor for an empty string
|
||||||
wxString() {}
|
wxString() {}
|
||||||
|
|
||||||
// copy ctor
|
// copy ctor
|
||||||
wxString(const wxStringImpl& stringSrc) : m_impl(stringSrc) { }
|
wxString(const wxStringImpl& stringSrc) : m_impl(stringSrc) { }
|
||||||
wxString(const wxString& stringSrc) : m_impl(stringSrc) { }
|
wxString(const wxString& stringSrc) : m_impl(stringSrc.m_impl) { }
|
||||||
|
|
||||||
// string containing nRepeat copies of ch
|
// string containing nRepeat copies of ch
|
||||||
wxString(wxUniChar ch, size_t nRepeat = 1)
|
wxString(wxUniChar ch, size_t nRepeat = 1)
|
||||||
: m_impl(nRepeat, ch) { }
|
{ assign(nRepeat, ch); }
|
||||||
wxString(size_t nRepeat, wxUniChar ch)
|
wxString(size_t nRepeat, wxUniChar ch)
|
||||||
: m_impl(nRepeat, ch) { }
|
{ assign(nRepeat, ch); }
|
||||||
wxString(wxUniCharRef ch, size_t nRepeat = 1)
|
wxString(wxUniCharRef ch, size_t nRepeat = 1)
|
||||||
: m_impl(nRepeat, ch) { }
|
{ assign(nRepeat, ch); }
|
||||||
wxString(size_t nRepeat, wxUniCharRef ch)
|
wxString(size_t nRepeat, wxUniCharRef ch)
|
||||||
: m_impl(nRepeat, ch) { }
|
{ assign(nRepeat, ch); }
|
||||||
wxString(char ch, size_t nRepeat = 1)
|
wxString(char ch, size_t nRepeat = 1)
|
||||||
: m_impl(nRepeat, ch) { }
|
{ assign(nRepeat, ch); }
|
||||||
wxString(size_t nRepeat, char ch)
|
wxString(size_t nRepeat, char ch)
|
||||||
: m_impl(nRepeat, ch) { }
|
{ assign(nRepeat, ch); }
|
||||||
wxString(wchar_t ch, size_t nRepeat = 1)
|
wxString(wchar_t ch, size_t nRepeat = 1)
|
||||||
: m_impl(nRepeat, ch) { }
|
{ assign(nRepeat, ch); }
|
||||||
wxString(size_t nRepeat, wchar_t ch)
|
wxString(size_t nRepeat, wchar_t ch)
|
||||||
: m_impl(nRepeat, ch) { }
|
{ assign(nRepeat, ch); }
|
||||||
// ctor takes first nLength characters from C string
|
|
||||||
// (default value of npos means take all the string)
|
|
||||||
wxString(const wxChar *psz)
|
|
||||||
: m_impl(psz ? psz : wxT("")) { }
|
|
||||||
wxString(const wxChar *psz, size_t nLength)
|
|
||||||
: m_impl(psz, nLength) { }
|
|
||||||
wxString(const wxChar *psz,
|
|
||||||
const wxMBConv& WXUNUSED(conv),
|
|
||||||
size_t nLength = npos)
|
|
||||||
: m_impl(psz, nLength == npos ? wxStrlen(psz) : nLength) { }
|
|
||||||
|
|
||||||
// even if we're not built with wxUSE_STL == 1 it is very convenient to allow
|
// ctors from char* strings:
|
||||||
// implicit conversions from std::string to wxString as this allows to use
|
wxString(const char *psz)
|
||||||
// the same strings in non-GUI and GUI code, however we don't want to
|
: m_impl(ImplStr(psz)) {}
|
||||||
// unconditionally add this ctor as it would make wx lib dependent on
|
wxString(const char *psz, const wxMBConv& conv)
|
||||||
// libstdc++ on some Linux versions which is bad, so instead we ask the
|
: m_impl(ImplStr(psz, conv)) {}
|
||||||
// client code to define this wxUSE_STD_STRING symbol if they need it
|
wxString(const char *psz, size_t nLength)
|
||||||
#if wxUSE_STD_STRING && !wxUSE_STL_BASED_WXSTRING
|
{ assign(psz, nLength); }
|
||||||
wxString(const wxStdString& s)
|
wxString(const char *psz, const wxMBConv& conv, size_t nLength)
|
||||||
: m_impl(s.c_str()) { } // FIXME-UTF8: this is broken for embedded 0s
|
{
|
||||||
#endif // wxUSE_STD_STRING && !wxUSE_STL_BASED_WXSTRING
|
SubstrBufFromMB str(ImplStr(psz, nLength, conv));
|
||||||
|
m_impl.assign(str.data, str.len);
|
||||||
|
}
|
||||||
|
|
||||||
#if wxUSE_UNICODE
|
// and unsigned char*:
|
||||||
// from multibyte string
|
wxString(const unsigned char *psz)
|
||||||
wxString(const char *psz,
|
: m_impl(ImplStr((const char*)psz)) {}
|
||||||
const wxMBConv& conv = wxConvLibc,
|
wxString(const unsigned char *psz, const wxMBConv& conv)
|
||||||
size_t nLength = npos);
|
: m_impl(ImplStr((const char*)psz, conv)) {}
|
||||||
// from multibyte string for ANSI compatibility, with wxConvLibc
|
wxString(const unsigned char *psz, size_t nLength)
|
||||||
wxString(const char *psz, size_t nLength);
|
{ assign((const char*)psz, nLength); }
|
||||||
// from wxWCharBuffer (i.e. return from wxGetString)
|
wxString(const unsigned char *psz, const wxMBConv& conv, size_t nLength)
|
||||||
wxString(const wxWCharBuffer& psz) : m_impl(psz.data()) { }
|
{
|
||||||
#else // ANSI
|
SubstrBufFromMB str(ImplStr((const char*)psz, nLength, conv));
|
||||||
// from C string (for compilers using unsigned char)
|
m_impl.assign(str.data, str.len);
|
||||||
wxString(const unsigned char* psz)
|
}
|
||||||
: m_impl((const char*)psz) { }
|
|
||||||
// from part of C string (for compilers using unsigned char)
|
|
||||||
wxString(const unsigned char* psz, size_t nLength)
|
|
||||||
: m_impl((const char*)psz, nLength) { }
|
|
||||||
|
|
||||||
#if wxUSE_WCHAR_T
|
// ctors from wchar_t* strings:
|
||||||
// from wide (Unicode) string
|
wxString(const wchar_t *pwz)
|
||||||
wxString(const wchar_t *pwz,
|
: m_impl(ImplStr(pwz)) {}
|
||||||
const wxMBConv& conv = wxConvLibc,
|
wxString(const wchar_t *pwz, const wxMBConv& WXUNUSED(conv))
|
||||||
size_t nLength = npos);
|
: m_impl(ImplStr(pwz)) {}
|
||||||
// from wide string for Unicode compatibility, with wxConvLibc
|
wxString(const wchar_t *pwz, size_t nLength)
|
||||||
wxString(const wchar_t *pwz, size_t nLength);
|
{ assign(pwz, nLength); }
|
||||||
#endif // !wxUSE_WCHAR_T
|
wxString(const wchar_t *pwz, const wxMBConv& WXUNUSED(conv), size_t nLength)
|
||||||
|
{ assign(pwz, nLength); }
|
||||||
|
|
||||||
// from wxCharBuffer
|
wxString(const wxCharBuffer& buf)
|
||||||
wxString(const wxCharBuffer& psz)
|
{ assign(buf.data()); } // FIXME-UTF8: fix for embedded NUL and buffer length
|
||||||
: m_impl(psz) { }
|
wxString(const wxWCharBuffer& buf)
|
||||||
#endif // Unicode/ANSI
|
{ assign(buf.data()); } // FIXME-UTF8: fix for embedded NUL and buffer length
|
||||||
|
|
||||||
wxString(const wxCStrData& cstr)
|
wxString(const wxCStrData& cstr)
|
||||||
: m_impl(cstr.AsString().m_impl) { }
|
: m_impl(cstr.AsString().m_impl) { }
|
||||||
@ -990,8 +981,8 @@ public:
|
|||||||
|
|
||||||
// overloaded assignment
|
// overloaded assignment
|
||||||
// from another wxString
|
// from another wxString
|
||||||
wxString& operator=(const wxStringImpl& stringSrc)
|
wxString& operator=(const wxString& stringSrc)
|
||||||
{ m_impl = stringSrc; return *this; }
|
{ m_impl = stringSrc.m_impl; return *this; }
|
||||||
wxString& operator=(const wxCStrData& cstr)
|
wxString& operator=(const wxCStrData& cstr)
|
||||||
{ return *this = cstr.AsString(); }
|
{ return *this = cstr.AsString(); }
|
||||||
// from a character
|
// from a character
|
||||||
@ -1008,31 +999,25 @@ public:
|
|||||||
// from a C string - STL probably will crash on NULL,
|
// from a C string - STL probably will crash on NULL,
|
||||||
// so we need to compensate in that case
|
// so we need to compensate in that case
|
||||||
#if wxUSE_STL_BASED_WXSTRING
|
#if wxUSE_STL_BASED_WXSTRING
|
||||||
wxString& operator=(const wxChar *psz)
|
wxString& operator=(const char *psz)
|
||||||
{ if(psz) m_impl = psz; else Clear(); return *this; }
|
{ if (psz) m_impl = ImplStr(psz); else Clear(); return *this; }
|
||||||
|
wxString& operator=(const wchar_t *pwz)
|
||||||
|
{ if (pwz) m_impl = ImplStr(pwz); else Clear(); return *this; }
|
||||||
#else
|
#else
|
||||||
wxString& operator=(const wxChar *psz)
|
wxString& operator=(const char *psz)
|
||||||
{ m_impl = psz; return *this; }
|
{ m_impl = ImplStr(psz); return *this; }
|
||||||
|
wxString& operator=(const wchar_t *pwz)
|
||||||
|
{ m_impl = ImplStr(pwz); return *this; }
|
||||||
#endif
|
#endif
|
||||||
|
wxString& operator=(const unsigned char *psz)
|
||||||
|
{ return operator=((const char*)psz); }
|
||||||
|
|
||||||
#if wxUSE_UNICODE
|
|
||||||
// from wxWCharBuffer
|
// from wxWCharBuffer
|
||||||
wxString& operator=(const wxWCharBuffer& s)
|
wxString& operator=(const wxWCharBuffer& s)
|
||||||
{ (void) operator=((const wchar_t *)s); return *this; }
|
{ return operator=(s.data()); } // FIXME-UTF8: fix for embedded NULs
|
||||||
// from C string
|
|
||||||
wxString& operator=(const char* psz)
|
|
||||||
{ return operator=(wxString(psz)); }
|
|
||||||
#else // ANSI
|
|
||||||
// from another kind of C string
|
|
||||||
wxString& operator=(const unsigned char* psz);
|
|
||||||
#if wxUSE_WCHAR_T
|
|
||||||
// from a wide string
|
|
||||||
wxString& operator=(const wchar_t *pwz);
|
|
||||||
#endif
|
|
||||||
// from wxCharBuffer
|
// from wxCharBuffer
|
||||||
wxString& operator=(const wxCharBuffer& psz)
|
wxString& operator=(const wxCharBuffer& s)
|
||||||
{ (void) operator=((const char *)psz); return *this; }
|
{ return operator=(s.data()); } // FIXME-UTF8: fix for embedded NULs
|
||||||
#endif // Unicode/ANSI
|
|
||||||
|
|
||||||
// string concatenation
|
// string concatenation
|
||||||
// in place concatenation
|
// in place concatenation
|
||||||
@ -2201,6 +2186,10 @@ wxDEFINE_ALL_COMPARISONS(const char *, const wxString&, wxCMP_CHAR_STRING)
|
|||||||
|
|
||||||
WXDLLIMPEXP_BASE wxSTD ostream& operator<<(wxSTD ostream&, const wxString&);
|
WXDLLIMPEXP_BASE wxSTD ostream& operator<<(wxSTD ostream&, const wxString&);
|
||||||
WXDLLIMPEXP_BASE wxSTD ostream& operator<<(wxSTD ostream&, const wxCStrData&);
|
WXDLLIMPEXP_BASE wxSTD ostream& operator<<(wxSTD ostream&, const wxCStrData&);
|
||||||
|
WXDLLIMPEXP_BASE wxSTD ostream& operator<<(wxSTD ostream&, const wxCharBuffer&);
|
||||||
|
#ifndef __BORLANDC__
|
||||||
|
WXDLLIMPEXP_BASE wxSTD ostream& operator<<(wxSTD ostream&, const wxWCharBuffer&);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // wxSTD_STRING_COMPATIBILITY
|
#endif // wxSTD_STRING_COMPATIBILITY
|
||||||
|
|
||||||
|
@ -75,13 +75,9 @@ const size_t wxString::npos = (size_t) -1;
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
wxSTD ostream& operator<<(wxSTD ostream& os, const wxString& str)
|
|
||||||
{
|
|
||||||
return os << str.c_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
wxSTD ostream& operator<<(wxSTD ostream& os, const wxCStrData& str)
|
wxSTD ostream& operator<<(wxSTD ostream& os, const wxCStrData& str)
|
||||||
{
|
{
|
||||||
|
// FIXME-UTF8: always, not only if wxUSE_UNICODE
|
||||||
#if wxUSE_UNICODE && !defined(__BORLANDC__)
|
#if wxUSE_UNICODE && !defined(__BORLANDC__)
|
||||||
return os << str.AsWChar();
|
return os << str.AsWChar();
|
||||||
#else
|
#else
|
||||||
@ -89,6 +85,23 @@ wxSTD ostream& operator<<(wxSTD ostream& os, const wxCStrData& str)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxSTD ostream& operator<<(wxSTD ostream& os, const wxString& str)
|
||||||
|
{
|
||||||
|
return os << str.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
wxSTD ostream& operator<<(wxSTD ostream& os, const wxCharBuffer& str)
|
||||||
|
{
|
||||||
|
return os << str.data();
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef __BORLANDC__
|
||||||
|
wxSTD ostream& operator<<(wxSTD ostream& os, const wxWCharBuffer& str)
|
||||||
|
{
|
||||||
|
return os << str.data();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // wxUSE_STD_IOSTREAM
|
#endif // wxUSE_STD_IOSTREAM
|
||||||
|
|
||||||
// ===========================================================================
|
// ===========================================================================
|
||||||
@ -102,7 +115,7 @@ wxSTD ostream& operator<<(wxSTD ostream& os, const wxCStrData& str)
|
|||||||
#if wxUSE_UNICODE
|
#if wxUSE_UNICODE
|
||||||
/* static */
|
/* static */
|
||||||
wxString::SubstrBufFromMB wxString::ConvertStr(const char *psz, size_t nLength,
|
wxString::SubstrBufFromMB wxString::ConvertStr(const char *psz, size_t nLength,
|
||||||
const wxMBConv& conv)
|
const wxMBConv& conv)
|
||||||
{
|
{
|
||||||
// anything to do?
|
// anything to do?
|
||||||
if ( !psz || nLength == 0 )
|
if ( !psz || nLength == 0 )
|
||||||
@ -121,7 +134,7 @@ wxString::SubstrBufFromMB wxString::ConvertStr(const char *psz, size_t nLength,
|
|||||||
#else
|
#else
|
||||||
/* static */
|
/* static */
|
||||||
wxString::SubstrBufFromWC wxString::ConvertStr(const wchar_t *pwz, size_t nLength,
|
wxString::SubstrBufFromWC wxString::ConvertStr(const wchar_t *pwz, size_t nLength,
|
||||||
const wxMBConv& conv)
|
const wxMBConv& conv)
|
||||||
{
|
{
|
||||||
// anything to do?
|
// anything to do?
|
||||||
if ( !pwz || nLength == 0 )
|
if ( !pwz || nLength == 0 )
|
||||||
@ -142,32 +155,6 @@ wxString::SubstrBufFromWC wxString::ConvertStr(const wchar_t *pwz, size_t nLengt
|
|||||||
|
|
||||||
#if wxUSE_UNICODE
|
#if wxUSE_UNICODE
|
||||||
|
|
||||||
// from multibyte string
|
|
||||||
wxString::wxString(const char *psz, const wxMBConv& conv, size_t nLength)
|
|
||||||
{
|
|
||||||
// FIXME-UTF8: this will need changes
|
|
||||||
|
|
||||||
// anything to do?
|
|
||||||
if ( psz && nLength != 0 )
|
|
||||||
{
|
|
||||||
if ( nLength == npos )
|
|
||||||
{
|
|
||||||
nLength = wxNO_LEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t nLenWide;
|
|
||||||
wxWCharBuffer wbuf = conv.cMB2WC(psz, nLength, &nLenWide);
|
|
||||||
|
|
||||||
if ( nLenWide )
|
|
||||||
assign(wbuf, nLenWide);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
wxString::wxString(const char *psz, size_t nLength)
|
|
||||||
{
|
|
||||||
assign(psz, nLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Convert wxString in Unicode mode to a multi-byte string
|
//Convert wxString in Unicode mode to a multi-byte string
|
||||||
const wxCharBuffer wxString::mb_str(const wxMBConv& conv) const
|
const wxCharBuffer wxString::mb_str(const wxMBConv& conv) const
|
||||||
{
|
{
|
||||||
@ -178,33 +165,6 @@ const wxCharBuffer wxString::mb_str(const wxMBConv& conv) const
|
|||||||
|
|
||||||
#if wxUSE_WCHAR_T
|
#if wxUSE_WCHAR_T
|
||||||
|
|
||||||
// from wide string
|
|
||||||
wxString::wxString(const wchar_t *pwz, const wxMBConv& conv, size_t nLength)
|
|
||||||
{
|
|
||||||
// FIXME-UTF8: this will need changes
|
|
||||||
|
|
||||||
// anything to do?
|
|
||||||
if ( pwz && nLength != 0 )
|
|
||||||
{
|
|
||||||
if ( nLength == npos )
|
|
||||||
{
|
|
||||||
nLength = wxNO_LEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t nLenMB;
|
|
||||||
wxCharBuffer buf = conv.cWC2MB(pwz, nLength, &nLenMB);
|
|
||||||
|
|
||||||
if ( nLenMB )
|
|
||||||
assign(buf, nLenMB);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
wxString::wxString(const wchar_t *pwz, size_t nLength)
|
|
||||||
{
|
|
||||||
assign(pwz, nLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Converts this string to a wide character string if unicode
|
//Converts this string to a wide character string if unicode
|
||||||
//mode is not enabled and wxUSE_WCHAR_T is enabled
|
//mode is not enabled and wxUSE_WCHAR_T is enabled
|
||||||
const wxWCharBuffer wxString::wc_str(const wxMBConv& conv) const
|
const wxWCharBuffer wxString::wc_str(const wxMBConv& conv) const
|
||||||
|
Loading…
Reference in New Issue
Block a user