} // namespace wxPrivate
+
+// Reference-counted character buffer for storing string data. The buffer
+// is only valid for as long as the "parent" object that provided the data
+// is valid; see wxCharTypeBuffer<T> for persistent variant.
template <typename T>
-class wxCharTypeBuffer
+class wxScopedCharTypeBuffer
{
public:
typedef T CharType;
- wxCharTypeBuffer(const CharType *str = NULL)
+ wxScopedCharTypeBuffer()
{
- if ( str )
- m_data = new Data(wxStrdup(str));
- else
- m_data = GetNullData();
+ m_data = GetNullData();
}
- wxCharTypeBuffer(size_t len)
+ // Creates "non-owned" buffer, i.e. 'str' is not owned by the buffer
+ // and doesn't get freed by dtor. Used e.g. to point to wxString's internal
+ // storage.
+ static const wxScopedCharTypeBuffer CreateNonOwned(const CharType *str)
{
- m_data = new Data((CharType *)malloc((len + 1)*sizeof(CharType)));
- m_data->Get()[len] = (CharType)0;
+ wxScopedCharTypeBuffer buf;
+ if ( str )
+ buf.m_data = new Data(const_cast<CharType*>(str), Data::NonOwned);
+ return buf;
}
- static const wxCharTypeBuffer CreateNonOwned(const CharType *str)
+ // Creates "owned" buffer, i.e. takes over ownership of 'str' and frees it
+ // in dtor (if ref.count reaches 0).
+ static const wxScopedCharTypeBuffer CreateOwned(const CharType *str)
{
- wxCharTypeBuffer buf;
+ wxScopedCharTypeBuffer buf;
if ( str )
- buf.m_data = new Data(const_cast<CharType*>(str), Data::NonOwned);
+ buf.m_data = new Data(wxStrdup(str));
return buf;
}
- ~wxCharTypeBuffer()
+ wxScopedCharTypeBuffer(const wxScopedCharTypeBuffer& src)
+ {
+ m_data = src.m_data;
+ IncRef();
+ }
+
+ wxScopedCharTypeBuffer& operator=(const wxScopedCharTypeBuffer& src)
+ {
+ if ( &src == this )
+ return *this;
+
+ DecRef();
+ m_data = src.m_data;
+ IncRef();
+
+ return *this;
+ }
+
+ ~wxScopedCharTypeBuffer()
{
DecRef();
}
CharType * const p = m_data->Get();
- wxCharTypeBuffer *self = const_cast<wxCharTypeBuffer*>(this);
+ wxScopedCharTypeBuffer *self = const_cast<wxScopedCharTypeBuffer*>(this);
self->m_data->Set(NULL);
self->DecRef();
DecRef();
}
- wxCharTypeBuffer(const wxCharTypeBuffer& src)
- {
- m_data = src.m_data;
- IncRef();
- }
-
- wxCharTypeBuffer& operator=(const CharType *str)
- {
- DecRef();
-
- if ( str )
- m_data = new Data(wxStrdup(str));
- return *this;
- }
-
- wxCharTypeBuffer& operator=(const wxCharTypeBuffer& src)
- {
- if ( &src == this )
- return *this;
-
- DecRef();
- m_data = src.m_data;
- IncRef();
-
- return *this;
- }
-
- bool extend(size_t len)
- {
- wxASSERT_MSG( m_data->m_owned, _T("cannot extend non-owned buffer") );
- wxASSERT_MSG( m_data->m_ref == 1, _T("can't extend shared buffer") );
-
- CharType *str =
- (CharType *)realloc(data(), (len + 1) * sizeof(CharType));
- if ( !str )
- return false;
-
- if ( m_data == GetNullData() )
- {
- m_data = new Data(str);
- }
- else
- {
- m_data->Set(str);
- m_data->m_owned = true;
- }
-
- return true;
- }
-
CharType *data() { return m_data->Get(); }
const CharType *data() const { return m_data->Get(); }
operator const CharType *() const { return data(); }
CharType operator[](size_t n) const { return data()[n]; }
-private:
+protected:
// reference-counted data
struct Data : public wxPrivate::UntypedBufferData
{
m_data = GetNullData();
}
-private:
+ // sets this object to a be copy of 'other'; if 'src' is non-owned,
+ // a deep copy is made and 'this' will contain new instance of the data
+ void MakeOwnedCopyOf(const wxScopedCharTypeBuffer& src)
+ {
+ this->DecRef();
+
+ if ( src.m_data == this->GetNullData() )
+ {
+ this->m_data = this->GetNullData();
+ }
+ else if ( src.m_data->m_owned )
+ {
+ this->m_data = src.m_data;
+ this->IncRef();
+ }
+ else
+ {
+ // if the scoped buffer had non-owned data, we have to make
+ // a copy here, because src.m_data->m_str is valid only for as long
+ // as 'src' exists
+ this->m_data = new Data(wxStrdup(src.m_data->Get()));
+ }
+ }
+
+protected:
Data *m_data;
};
+typedef wxScopedCharTypeBuffer<char> wxScopedCharBuffer;
+typedef wxScopedCharTypeBuffer<wchar_t> wxScopedWCharBuffer;
+
+
+// this buffer class always stores data in "owned" (persistent) manner
+template <typename T>
+class wxCharTypeBuffer : public wxScopedCharTypeBuffer<T>
+{
+protected:
+ typedef typename wxScopedCharTypeBuffer<T>::Data Data;
+
+public:
+ typedef T CharType;
+
+ wxCharTypeBuffer(const CharType *str = NULL)
+ {
+ if ( str )
+ this->m_data = new Data(wxStrdup(str));
+ else
+ this->m_data = this->GetNullData();
+ }
+
+ wxCharTypeBuffer(size_t len)
+ {
+ this->m_data = new Data((CharType *)malloc((len + 1)*sizeof(CharType)));
+ this->m_data->Get()[len] = (CharType)0;
+ }
+
+ wxCharTypeBuffer(const wxCharTypeBuffer& src)
+ {
+ this->m_data = src.m_data;
+ this->IncRef();
+ }
+
+ wxCharTypeBuffer& operator=(const CharType *str)
+ {
+ this->DecRef();
+
+ if ( str )
+ this->m_data = new Data(wxStrdup(str));
+ return *this;
+ }
+
+ wxCharTypeBuffer& operator=(const wxCharTypeBuffer& src)
+ {
+ if ( &src == this )
+ return *this;
+
+ this->DecRef();
+ this->m_data = src.m_data;
+ this->IncRef();
+
+ return *this;
+ }
+
+ wxCharTypeBuffer(const wxScopedCharTypeBuffer<T>& src)
+ {
+ MakeOwnedCopyOf(src);
+ }
+
+ wxCharTypeBuffer& operator=(const wxScopedCharTypeBuffer<T>& src)
+ {
+ MakeOwnedCopyOf(src);
+ return *this;
+ }
+
+ bool extend(size_t len)
+ {
+ wxASSERT_MSG( this->m_data->m_owned, "cannot extend non-owned buffer" );
+ wxASSERT_MSG( this->m_data->m_ref == 1, "can't extend shared buffer" );
+
+ CharType *str =
+ (CharType *)realloc(this->data(), (len + 1) * sizeof(CharType));
+ if ( !str )
+ return false;
+
+ if ( this->m_data == this->GetNullData() )
+ {
+ this->m_data = new Data(str);
+ }
+ else
+ {
+ this->m_data->Set(str);
+ this->m_data->m_owned = true;
+ }
+
+ return true;
+ }
+};
+
WXDLLIMPEXP_TEMPLATE_INSTANCE_BASE( wxCharTypeBuffer<char> )
class wxCharBuffer : public wxCharTypeBuffer<char>
{
public:
typedef wxCharTypeBuffer<char> wxCharTypeBufferBase;
+ typedef wxScopedCharTypeBuffer<char> wxScopedCharTypeBufferBase;
wxCharBuffer(const wxCharTypeBufferBase& buf)
: wxCharTypeBufferBase(buf) {}
+ wxCharBuffer(const wxScopedCharTypeBufferBase& buf)
+ : wxCharTypeBufferBase(buf) {}
wxCharBuffer(const CharType *str = NULL) : wxCharTypeBufferBase(str) {}
wxCharBuffer(size_t len) : wxCharTypeBufferBase(len) {}
{
public:
typedef wxCharTypeBuffer<wchar_t> wxCharTypeBufferBase;
+ typedef wxScopedCharTypeBuffer<wchar_t> wxScopedCharTypeBufferBase;
wxWCharBuffer(const wxCharTypeBufferBase& buf)
: wxCharTypeBufferBase(buf) {}
+ wxWCharBuffer(const wxScopedCharTypeBufferBase& buf)
+ : wxCharTypeBufferBase(buf) {}
wxWCharBuffer(const CharType *str = NULL) : wxCharTypeBufferBase(str) {}
wxWCharBuffer(size_t len) : wxCharTypeBufferBase(len) {}
class wxWritableCharTypeBuffer : public wxCharTypeBuffer<T>
{
public:
- typedef typename wxCharTypeBuffer<T>::CharType CharType;
+ typedef typename wxScopedCharTypeBuffer<T>::CharType CharType;
- wxWritableCharTypeBuffer(const wxCharTypeBuffer<T>& src)
+ wxWritableCharTypeBuffer(const wxScopedCharTypeBuffer<T>& src)
: wxCharTypeBuffer<T>(src) {}
// FIXME-UTF8: this won't be needed after converting mb_str()/wc_str() to
// always return a buffer
+ // + we should derive this class from wxScopedCharTypeBuffer
+ // then
wxWritableCharTypeBuffer(const CharType *str = NULL)
: wxCharTypeBuffer<T>(str) {}
CtorString(const wchar_t *str) : m_str(str) {}
CtorString(const wxString& str) : m_str(str) {}
CtorString(const wxCStrData& str) : m_str(str) {}
- CtorString(const wxCharBuffer& str) : m_str(str) {}
- CtorString(const wxWCharBuffer& str) : m_str(str) {}
+ CtorString(const wxScopedCharBuffer& str) : m_str(str) {}
+ CtorString(const wxScopedWCharBuffer& str) : m_str(str) {}
operator const wxString*() const { return &m_str; }
wxString wxXmStringToString( const XmString& xmString );
XmString wxStringToXmString( const char* string );
-inline XmString wxStringToXmString( const wxCharBuffer& string )
+inline XmString wxStringToXmString( const wxScopedCharBuffer& string )
{ return wxStringToXmString(string.data()); }
inline XmString wxStringToXmString( const wxString& string )
{ return wxStringToXmString((const char*)string.mb_str()); }
operator const void*() const { return AsChar(); }
- inline const wxCharBuffer AsCharBuf() const;
- inline const wxWCharBuffer AsWCharBuf() const;
+ // returns buffers that are valid as long as the associated wxString exists
+ inline const wxScopedCharBuffer AsCharBuf() const;
+ inline const wxScopedWCharBuffer AsWCharBuf() const;
inline wxString AsString() const;
#if wxUSE_UNICODE_UTF8
// even char* -> char* needs conversion, from locale charset to UTF-8
- typedef SubstrBufFromType<wxCharBuffer> SubstrBufFromWC;
- typedef SubstrBufFromType<wxCharBuffer> SubstrBufFromMB;
+ typedef SubstrBufFromType<wxScopedCharBuffer> SubstrBufFromWC;
+ typedef SubstrBufFromType<wxScopedCharBuffer> SubstrBufFromMB;
#elif wxUSE_UNICODE_WCHAR
- typedef SubstrBufFromType<const wchar_t*> SubstrBufFromWC;
- typedef SubstrBufFromType<wxWCharBuffer> SubstrBufFromMB;
+ typedef SubstrBufFromType<const wchar_t*> SubstrBufFromWC;
+ typedef SubstrBufFromType<wxScopedWCharBuffer> SubstrBufFromMB;
#else
- typedef SubstrBufFromType<const char*> SubstrBufFromMB;
- typedef SubstrBufFromType<wxCharBuffer> SubstrBufFromWC;
+ typedef SubstrBufFromType<const char*> SubstrBufFromMB;
+ typedef SubstrBufFromType<wxScopedCharBuffer> SubstrBufFromWC;
#endif
{ return str ? str : wxT(""); }
static const SubstrBufFromWC ImplStr(const wchar_t* str, size_t n)
{ return SubstrBufFromWC(str, (str && n == npos) ? wxWcslen(str) : n); }
- static wxWCharBuffer ImplStr(const char* str,
- const wxMBConv& conv = wxConvLibc)
+ static wxScopedWCharBuffer ImplStr(const char* str,
+ const wxMBConv& conv = wxConvLibc)
{ return ConvertStr(str, npos, conv).data; }
static SubstrBufFromMB ImplStr(const char* str, size_t n,
const wxMBConv& conv = wxConvLibc)
static const SubstrBufFromMB ImplStr(const char* str, size_t n,
const wxMBConv& WXUNUSED(conv) = wxConvLibc)
{ return SubstrBufFromMB(str, (str && n == npos) ? wxStrlen(str) : n); }
- static wxCharBuffer ImplStr(const wchar_t* str)
+ static wxScopedCharBuffer ImplStr(const wchar_t* str)
{ return ConvertStr(str, npos, wxConvLibc).data; }
static SubstrBufFromWC ImplStr(const wchar_t* str, size_t n)
{ return ConvertStr(str, n, wxConvLibc); }
#else // wxUSE_UNICODE_UTF8
- static wxCharBuffer ImplStr(const char* str,
- const wxMBConv& conv = wxConvLibc)
+ static wxScopedCharBuffer ImplStr(const char* str,
+ const wxMBConv& conv = wxConvLibc)
{ return ConvertStr(str, npos, conv).data; }
static SubstrBufFromMB ImplStr(const char* str, size_t n,
const wxMBConv& conv = wxConvLibc)
{ return ConvertStr(str, n, conv); }
- static wxCharBuffer ImplStr(const wchar_t* str)
+ static wxScopedCharBuffer ImplStr(const wchar_t* str)
{ return ConvertStr(str, npos, wxMBConvUTF8()).data; }
static SubstrBufFromWC ImplStr(const wchar_t* str, size_t n)
{ return ConvertStr(str, n, wxMBConvUTF8()); }
wxString(const wchar_t *pwz, const wxMBConv& WXUNUSED(conv), size_t nLength)
{ assign(pwz, nLength); }
- wxString(const wxCharBuffer& buf)
+ wxString(const wxScopedCharBuffer& buf)
{ assign(buf.data()); } // FIXME-UTF8: fix for embedded NUL and buffer length
- wxString(const wxWCharBuffer& buf)
+ wxString(const wxScopedWCharBuffer& buf)
{ assign(buf.data()); } // FIXME-UTF8: fix for embedded NUL and buffer length
// NB: this version uses m_impl.c_str() to force making a copy of the
static wxString FromAscii(const char *ascii, size_t len);
static wxString FromAscii(const char *ascii);
static wxString FromAscii(char ascii);
- const wxCharBuffer ToAscii() const;
+ const wxScopedCharBuffer ToAscii() const;
#else // ANSI
static wxString FromAscii(const char *ascii) { return wxString( ascii ); }
static wxString FromAscii(const char *ascii, size_t len)
"string must be valid UTF-8" );
return s;
}
- const wxCharBuffer utf8_str() const { return mb_str(wxMBConvUTF8()); }
- const wxCharBuffer ToUTF8() const { return utf8_str(); }
+ const wxScopedCharBuffer utf8_str() const { return mb_str(wxMBConvUTF8()); }
+ const wxScopedCharBuffer ToUTF8() const { return utf8_str(); }
#else // ANSI
static wxString FromUTF8(const char *utf8)
{ return wxString(wxMBConvUTF8().cMB2WC(utf8)); }
static wxString FromUTF8(const char *utf8, size_t len)
{
size_t wlen;
- wxWCharBuffer buf(wxMBConvUTF8().cMB2WC(utf8, len == npos ? wxNO_LEN : len, &wlen));
+ wxScopedWCharBuffer buf(wxMBConvUTF8().cMB2WC(utf8, len == npos ? wxNO_LEN : len, &wlen));
return wxString(buf.data(), wlen);
}
static wxString FromUTF8Unchecked(const char *utf8, size_t len = npos)
{
size_t wlen;
- wxWCharBuffer buf(wxMBConvUTF8().cMB2WC(utf8,
- len == npos ? wxNO_LEN : len,
- &wlen));
+ wxScopedWCharBuffer buf
+ (
+ wxMBConvUTF8().cMB2WC
+ (
+ utf8,
+ len == npos ? wxNO_LEN : len,
+ &wlen
+ )
+ );
wxASSERT_MSG( !utf8 || !*utf8 || wlen,
"string must be valid UTF-8" );
return wxString(buf.data(), wlen);
}
- const wxCharBuffer utf8_str() const
+ const wxScopedCharBuffer utf8_str() const
{ return wxMBConvUTF8().cWC2MB(wc_str()); }
- const wxCharBuffer ToUTF8() const { return utf8_str(); }
+ const wxScopedCharBuffer ToUTF8() const { return utf8_str(); }
#endif
// functions for storing binary data in wxString:
// version for NUL-terminated data:
static wxString From8BitData(const char *data)
{ return wxString(data, wxConvISO8859_1); }
- const wxCharBuffer To8BitData() const { return mb_str(wxConvISO8859_1); }
+ const wxScopedCharBuffer To8BitData() const
+ { return mb_str(wxConvISO8859_1); }
#else // ANSI
static wxString From8BitData(const char *data, size_t len)
{ return wxString(data, len); }
#if wxUSE_UTF8_LOCALE_ONLY
const char* mb_str() const { return wx_str(); }
- const wxCharBuffer mb_str(const wxMBConv& conv) const;
+ const wxScopedCharBuffer mb_str(const wxMBConv& conv) const;
#else
- const wxCharBuffer mb_str(const wxMBConv& conv = wxConvLibc) const;
+ const wxScopedCharBuffer mb_str(const wxMBConv& conv = wxConvLibc) const;
#endif
const wxWX2MBbuf mbc_str() const { return mb_str(*wxConvCurrent); }
#if wxUSE_UNICODE_WCHAR
const wchar_t* wc_str() const { return wx_str(); }
#elif wxUSE_UNICODE_UTF8
- const wxWCharBuffer wc_str() const;
+ const wxScopedWCharBuffer wc_str() const;
#endif
// for compatibility with !wxUSE_UNICODE version
const wxWX2WCbuf wc_str(const wxMBConv& WXUNUSED(conv)) const
{ return wc_str(); }
#if wxMBFILES
- const wxCharBuffer fn_str() const { return mb_str(wxConvFile); }
+ const wxScopedCharBuffer fn_str() const { return mb_str(wxConvFile); }
#else // !wxMBFILES
const wxWX2WCbuf fn_str() const { return wc_str(); }
#endif // wxMBFILES/!wxMBFILES
const wxWX2MBbuf mbc_str() const { return mb_str(); }
#if wxUSE_WCHAR_T
- const wxWCharBuffer wc_str(const wxMBConv& conv = wxConvLibc) const;
+ const wxScopedWCharBuffer wc_str(const wxMBConv& conv = wxConvLibc) const;
#endif // wxUSE_WCHAR_T
- const wxCharBuffer fn_str() const { return wxConvFile.cWC2WX( wc_str( wxConvLibc ) ); }
+ const wxScopedCharBuffer fn_str() const
+ { return wxConvFile.cWC2WX( wc_str( wxConvLibc ) ); }
#endif // Unicode/ANSI
#if wxUSE_UNICODE_UTF8
- const wxWCharBuffer t_str() const { return wc_str(); }
+ const wxScopedWCharBuffer t_str() const { return wc_str(); }
#elif wxUSE_UNICODE_WCHAR
const wchar_t* t_str() const { return wx_str(); }
#else
wxString& operator=(const unsigned char *psz)
{ return operator=((const char*)psz); }
- // from wxWCharBuffer
- wxString& operator=(const wxWCharBuffer& s)
+ // from wxScopedWCharBuffer
+ wxString& operator=(const wxScopedWCharBuffer& s)
{ return operator=(s.data()); } // FIXME-UTF8: fix for embedded NULs
- // from wxCharBuffer
- wxString& operator=(const wxCharBuffer& s)
+ // from wxScopedCharBuffer
+ wxString& operator=(const wxScopedCharBuffer& s)
{ return operator=(s.data()); } // FIXME-UTF8: fix for embedded NULs
// string concatenation
wxString& operator<<(wchar_t ch) { append(1, ch); return *this; }
// string += buffer (i.e. from wxGetString)
- wxString& operator<<(const wxWCharBuffer& s)
+ wxString& operator<<(const wxScopedWCharBuffer& s)
{ return operator<<((const wchar_t *)s); }
- wxString& operator<<(const wxCharBuffer& s)
+ wxString& operator<<(const wxScopedCharBuffer& s)
{ return operator<<((const char *)s); }
// string += C string
{ append(pwz); return *this; }
wxString& Append(const wxCStrData& psz)
{ append(psz); return *this; }
- wxString& Append(const wxCharBuffer& psz)
+ wxString& Append(const wxScopedCharBuffer& psz)
{ append(psz); return *this; }
- wxString& Append(const wxWCharBuffer& psz)
+ wxString& Append(const wxScopedWCharBuffer& psz)
{ append(psz); return *this; }
wxString& Append(const char* psz, size_t nLen)
{ append(psz, nLen); return *this; }
{ append(pwz, nLen); return *this; }
wxString& Append(const wxCStrData& psz, size_t nLen)
{ append(psz, nLen); return *this; }
- wxString& Append(const wxCharBuffer& psz, size_t nLen)
+ wxString& Append(const wxScopedCharBuffer& psz, size_t nLen)
{ append(psz, nLen); return *this; }
- wxString& Append(const wxWCharBuffer& psz, size_t nLen)
+ wxString& Append(const wxScopedWCharBuffer& psz, size_t nLen)
{ append(psz, nLen); return *this; }
// append count copies of given character
wxString& Append(wxUniChar ch, size_t count = 1u)
{ return compare(s); }
int Cmp(const wxCStrData& s) const
{ return compare(s); }
- int Cmp(const wxCharBuffer& s) const
+ int Cmp(const wxScopedCharBuffer& s) const
{ return compare(s); }
- int Cmp(const wxWCharBuffer& s) const
+ int Cmp(const wxScopedWCharBuffer& s) const
{ return compare(s); }
// same as Cmp() but not case-sensitive
int CmpNoCase(const wxString& s) const;
bool IsSameAs(const wxCStrData& str, bool compareWithCase = true) const
{ return IsSameAs(str.AsString(), compareWithCase); }
- bool IsSameAs(const wxCharBuffer& str, bool compareWithCase = true) const
+ bool IsSameAs(const wxScopedCharBuffer& str, bool compareWithCase = true) const
{ return IsSameAs(str.data(), compareWithCase); }
- bool IsSameAs(const wxWCharBuffer& str, bool compareWithCase = true) const
+ bool IsSameAs(const wxScopedWCharBuffer& str, bool compareWithCase = true) const
{ return IsSameAs(str.data(), compareWithCase); }
// comparison with a single character: returns true if equal
bool IsSameAs(wxUniChar c, bool compareWithCase = true) const;
int Find(const wxCStrData& sub) const
{ return Find(sub.AsString()); }
- int Find(const wxCharBuffer& sub) const
+ int Find(const wxScopedCharBuffer& sub) const
{ return Find(sub.data()); }
- int Find(const wxWCharBuffer& sub) const
+ int Find(const wxScopedWCharBuffer& sub) const
{ return Find(sub.data()); }
// replace first (or all of bReplaceAll) occurrences of substring with
wxString& append(const wxCStrData& str)
{ return append(str.AsString()); }
- wxString& append(const wxCharBuffer& str)
+ wxString& append(const wxScopedCharBuffer& str)
{ return append(str.data()); }
- wxString& append(const wxWCharBuffer& str)
+ wxString& append(const wxScopedWCharBuffer& str)
{ return append(str.data()); }
wxString& append(const wxCStrData& str, size_t n)
{ return append(str.AsString(), 0, n); }
- wxString& append(const wxCharBuffer& str, size_t n)
+ wxString& append(const wxScopedCharBuffer& str, size_t n)
{ return append(str.data(), n); }
- wxString& append(const wxWCharBuffer& str, size_t n)
+ wxString& append(const wxScopedWCharBuffer& str, size_t n)
{ return append(str.data(), n); }
// append n copies of ch
wxString& assign(const wxCStrData& str)
{ return assign(str.AsString()); }
- wxString& assign(const wxCharBuffer& str)
+ wxString& assign(const wxScopedCharBuffer& str)
{ return assign(str.data()); }
- wxString& assign(const wxWCharBuffer& str)
+ wxString& assign(const wxScopedWCharBuffer& str)
{ return assign(str.data()); }
wxString& assign(const wxCStrData& str, size_t len)
{ return assign(str.AsString(), len); }
- wxString& assign(const wxCharBuffer& str, size_t len)
+ wxString& assign(const wxScopedCharBuffer& str, size_t len)
{ return assign(str.data(), len); }
- wxString& assign(const wxWCharBuffer& str, size_t len)
+ wxString& assign(const wxScopedWCharBuffer& str, size_t len)
{ return assign(str.data(), len); }
// same as `= n copies of ch'
int compare(const wchar_t* sz) const;
int compare(const wxCStrData& str) const
{ return compare(str.AsString()); }
- int compare(const wxCharBuffer& str) const
+ int compare(const wxScopedCharBuffer& str) const
{ return compare(str.data()); }
- int compare(const wxWCharBuffer& str) const
+ int compare(const wxScopedWCharBuffer& str) const
{ return compare(str.data()); }
// comparison with a substring
int compare(size_t nStart, size_t nLen, const wxString& str) const;
SubstrBufFromWC str(ImplStr(sz, n));
return PosFromImpl(m_impl.find(str.data, PosToImpl(nStart), str.len));
}
- size_t find(const wxCharBuffer& s, size_t nStart = 0, size_t n = npos) const
+ size_t find(const wxScopedCharBuffer& s, size_t nStart = 0, size_t n = npos) const
{ return find(s.data(), nStart, n); }
- size_t find(const wxWCharBuffer& s, size_t nStart = 0, size_t n = npos) const
+ size_t find(const wxScopedWCharBuffer& s, size_t nStart = 0, size_t n = npos) const
{ return find(s.data(), nStart, n); }
size_t find(const wxCStrData& s, size_t nStart = 0, size_t n = npos) const
{ return find(s.AsWChar(), nStart, n); }
SubstrBufFromWC str(ImplStr(sz, n));
return PosFromImpl(m_impl.rfind(str.data, PosToImpl(nStart), str.len));
}
- size_t rfind(const wxCharBuffer& s, size_t nStart = npos, size_t n = npos) const
+ size_t rfind(const wxScopedCharBuffer& s, size_t nStart = npos, size_t n = npos) const
{ return rfind(s.data(), nStart, n); }
- size_t rfind(const wxWCharBuffer& s, size_t nStart = npos, size_t n = npos) const
+ size_t rfind(const wxScopedWCharBuffer& s, size_t nStart = npos, size_t n = npos) const
{ return rfind(s.data(), nStart, n); }
size_t rfind(const wxCStrData& s, size_t nStart = npos, size_t n = npos) const
{ return rfind(s.AsWChar(), nStart, n); }
// and additional overloads for the versions taking strings:
size_t find_first_of(const wxCStrData& sz, size_t nStart = 0) const
{ return find_first_of(sz.AsString(), nStart); }
- size_t find_first_of(const wxCharBuffer& sz, size_t nStart = 0) const
+ size_t find_first_of(const wxScopedCharBuffer& sz, size_t nStart = 0) const
{ return find_first_of(sz.data(), nStart); }
- size_t find_first_of(const wxWCharBuffer& sz, size_t nStart = 0) const
+ size_t find_first_of(const wxScopedWCharBuffer& sz, size_t nStart = 0) const
{ return find_first_of(sz.data(), nStart); }
size_t find_first_of(const wxCStrData& sz, size_t nStart, size_t n) const
{ return find_first_of(sz.AsWChar(), nStart, n); }
- size_t find_first_of(const wxCharBuffer& sz, size_t nStart, size_t n) const
+ size_t find_first_of(const wxScopedCharBuffer& sz, size_t nStart, size_t n) const
{ return find_first_of(sz.data(), nStart, n); }
- size_t find_first_of(const wxWCharBuffer& sz, size_t nStart, size_t n) const
+ size_t find_first_of(const wxScopedWCharBuffer& sz, size_t nStart, size_t n) const
{ return find_first_of(sz.data(), nStart, n); }
size_t find_last_of(const wxCStrData& sz, size_t nStart = 0) const
{ return find_last_of(sz.AsString(), nStart); }
- size_t find_last_of(const wxCharBuffer& sz, size_t nStart = 0) const
+ size_t find_last_of(const wxScopedCharBuffer& sz, size_t nStart = 0) const
{ return find_last_of(sz.data(), nStart); }
- size_t find_last_of(const wxWCharBuffer& sz, size_t nStart = 0) const
+ size_t find_last_of(const wxScopedWCharBuffer& sz, size_t nStart = 0) const
{ return find_last_of(sz.data(), nStart); }
size_t find_last_of(const wxCStrData& sz, size_t nStart, size_t n) const
{ return find_last_of(sz.AsWChar(), nStart, n); }
- size_t find_last_of(const wxCharBuffer& sz, size_t nStart, size_t n) const
+ size_t find_last_of(const wxScopedCharBuffer& sz, size_t nStart, size_t n) const
{ return find_last_of(sz.data(), nStart, n); }
- size_t find_last_of(const wxWCharBuffer& sz, size_t nStart, size_t n) const
+ size_t find_last_of(const wxScopedWCharBuffer& sz, size_t nStart, size_t n) const
{ return find_last_of(sz.data(), nStart, n); }
size_t find_first_not_of(const wxCStrData& sz, size_t nStart = 0) const
{ return find_first_not_of(sz.AsString(), nStart); }
- size_t find_first_not_of(const wxCharBuffer& sz, size_t nStart = 0) const
+ size_t find_first_not_of(const wxScopedCharBuffer& sz, size_t nStart = 0) const
{ return find_first_not_of(sz.data(), nStart); }
- size_t find_first_not_of(const wxWCharBuffer& sz, size_t nStart = 0) const
+ size_t find_first_not_of(const wxScopedWCharBuffer& sz, size_t nStart = 0) const
{ return find_first_not_of(sz.data(), nStart); }
size_t find_first_not_of(const wxCStrData& sz, size_t nStart, size_t n) const
{ return find_first_not_of(sz.AsWChar(), nStart, n); }
- size_t find_first_not_of(const wxCharBuffer& sz, size_t nStart, size_t n) const
+ size_t find_first_not_of(const wxScopedCharBuffer& sz, size_t nStart, size_t n) const
{ return find_first_not_of(sz.data(), nStart, n); }
- size_t find_first_not_of(const wxWCharBuffer& sz, size_t nStart, size_t n) const
+ size_t find_first_not_of(const wxScopedWCharBuffer& sz, size_t nStart, size_t n) const
{ return find_first_not_of(sz.data(), nStart, n); }
size_t find_last_not_of(const wxCStrData& sz, size_t nStart = 0) const
{ return find_last_not_of(sz.AsString(), nStart); }
- size_t find_last_not_of(const wxCharBuffer& sz, size_t nStart = 0) const
+ size_t find_last_not_of(const wxScopedCharBuffer& sz, size_t nStart = 0) const
{ return find_last_not_of(sz.data(), nStart); }
- size_t find_last_not_of(const wxWCharBuffer& sz, size_t nStart = 0) const
+ size_t find_last_not_of(const wxScopedWCharBuffer& sz, size_t nStart = 0) const
{ return find_last_not_of(sz.data(), nStart); }
size_t find_last_not_of(const wxCStrData& sz, size_t nStart, size_t n) const
{ return find_last_not_of(sz.AsWChar(), nStart, n); }
- size_t find_last_not_of(const wxCharBuffer& sz, size_t nStart, size_t n) const
+ size_t find_last_not_of(const wxScopedCharBuffer& sz, size_t nStart, size_t n) const
{ return find_last_not_of(sz.data(), nStart, n); }
- size_t find_last_not_of(const wxWCharBuffer& sz, size_t nStart, size_t n) const
+ size_t find_last_not_of(const wxScopedWCharBuffer& sz, size_t nStart, size_t n) const
{ return find_last_not_of(sz.data(), nStart, n); }
// string += string
m_impl += s.AsString().m_impl;
return *this;
}
- wxString& operator+=(const wxCharBuffer& s)
+ wxString& operator+=(const wxScopedCharBuffer& s)
{ return operator+=(s.data()); }
- wxString& operator+=(const wxWCharBuffer& s)
+ wxString& operator+=(const wxScopedWCharBuffer& s)
{ return operator+=(s.data()); }
// string += char
wxString& operator+=(wxUniChar ch)
template <>
struct wxStringAsBufHelper<char>
{
- static wxCharBuffer Get(const wxString& s, size_t *len)
+ static wxScopedCharBuffer Get(const wxString& s, size_t *len)
{
- wxCharBuffer buf(s.mb_str());
+ wxScopedCharBuffer buf(s.mb_str());
if ( len )
*len = buf ? strlen(buf) : 0;
return buf;
template <>
struct wxStringAsBufHelper<wchar_t>
{
- static wxWCharBuffer Get(const wxString& s, size_t *len)
+ static wxScopedWCharBuffer Get(const wxString& s, size_t *len)
{
if ( len )
*len = s.length();
- return wxWCharBuffer::CreateNonOwned(s.wx_str());
+ return wxScopedWCharBuffer::CreateNonOwned(s.wx_str());
}
};
template <>
struct wxStringAsBufHelper<char>
{
- static wxCharBuffer Get(const wxString& s, size_t *len)
+ static wxScopedCharBuffer Get(const wxString& s, size_t *len)
{
if ( len )
*len = s.utf8_length();
- return wxCharBuffer::CreateNonOwned(s.wx_str());
+ return wxScopedCharBuffer::CreateNonOwned(s.wx_str());
}
};
template <>
struct wxStringAsBufHelper<wchar_t>
{
- static wxWCharBuffer Get(const wxString& s, size_t *len)
+ static wxScopedWCharBuffer Get(const wxString& s, size_t *len)
{
- wxWCharBuffer wbuf(s.wc_str());
+ wxScopedWCharBuffer wbuf(s.wc_str());
if ( len )
*len = wxWcslen(wbuf);
return wbuf;
inline bool operator!=(const wxCStrData& s1, const wxString& s2)
{ return s1.AsString() != s2; }
-inline bool operator==(const wxString& s1, const wxWCharBuffer& s2)
+inline bool operator==(const wxString& s1, const wxScopedWCharBuffer& s2)
{ return (s1.Cmp((const wchar_t *)s2) == 0); }
-inline bool operator==(const wxWCharBuffer& s1, const wxString& s2)
+inline bool operator==(const wxScopedWCharBuffer& s1, const wxString& s2)
{ return (s2.Cmp((const wchar_t *)s1) == 0); }
-inline bool operator!=(const wxString& s1, const wxWCharBuffer& s2)
+inline bool operator!=(const wxString& s1, const wxScopedWCharBuffer& s2)
{ return (s1.Cmp((const wchar_t *)s2) != 0); }
-inline bool operator!=(const wxWCharBuffer& s1, const wxString& s2)
+inline bool operator!=(const wxScopedWCharBuffer& s1, const wxString& s2)
{ return (s2.Cmp((const wchar_t *)s1) != 0); }
-inline bool operator==(const wxString& s1, const wxCharBuffer& s2)
+inline bool operator==(const wxString& s1, const wxScopedCharBuffer& s2)
{ return (s1.Cmp((const char *)s2) == 0); }
-inline bool operator==(const wxCharBuffer& s1, const wxString& s2)
+inline bool operator==(const wxScopedCharBuffer& s1, const wxString& s2)
{ return (s2.Cmp((const char *)s1) == 0); }
-inline bool operator!=(const wxString& s1, const wxCharBuffer& s2)
+inline bool operator!=(const wxString& s1, const wxScopedCharBuffer& s2)
{ return (s1.Cmp((const char *)s2) != 0); }
-inline bool operator!=(const wxCharBuffer& s1, const wxString& s2)
+inline bool operator!=(const wxScopedCharBuffer& s1, const wxString& s2)
{ return (s2.Cmp((const char *)s1) != 0); }
-inline wxString operator+(const wxString& string, const wxWCharBuffer& buf)
+inline wxString operator+(const wxString& string, const wxScopedWCharBuffer& buf)
{ return string + (const wchar_t *)buf; }
-inline wxString operator+(const wxWCharBuffer& buf, const wxString& string)
+inline wxString operator+(const wxScopedWCharBuffer& buf, const wxString& string)
{ return (const wchar_t *)buf + string; }
-inline wxString operator+(const wxString& string, const wxCharBuffer& buf)
+inline wxString operator+(const wxString& string, const wxScopedCharBuffer& buf)
{ return string + (const char *)buf; }
-inline wxString operator+(const wxCharBuffer& buf, const wxString& string)
+inline wxString operator+(const wxScopedCharBuffer& buf, const wxString& string)
{ return (const char *)buf + string; }
// comparison with char
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 wxCharBuffer&);
+WXDLLIMPEXP_BASE wxSTD ostream& operator<<(wxSTD ostream&, const wxScopedCharBuffer&);
#ifndef __BORLANDC__
-WXDLLIMPEXP_BASE wxSTD ostream& operator<<(wxSTD ostream&, const wxWCharBuffer&);
+WXDLLIMPEXP_BASE wxSTD ostream& operator<<(wxSTD ostream&, const wxScopedWCharBuffer&);
#endif
#if wxUSE_UNICODE && defined(HAVE_WOSTREAM)
WXDLLIMPEXP_BASE wxSTD wostream& operator<<(wxSTD wostream&, const wxString&);
WXDLLIMPEXP_BASE wxSTD wostream& operator<<(wxSTD wostream&, const wxCStrData&);
-WXDLLIMPEXP_BASE wxSTD wostream& operator<<(wxSTD wostream&, const wxWCharBuffer&);
+WXDLLIMPEXP_BASE wxSTD wostream& operator<<(wxSTD wostream&, const wxScopedWCharBuffer&);
#endif // wxUSE_UNICODE && defined(HAVE_WOSTREAM)
}
#endif // wxUSE_UTF8_LOCALE_ONLY
-inline const wxCharBuffer wxCStrData::AsCharBuf() const
+inline const wxScopedCharBuffer wxCStrData::AsCharBuf() const
{
#if !wxUSE_UNICODE
- return wxCharBuffer::CreateNonOwned(AsChar());
+ return wxScopedCharBuffer::CreateNonOwned(AsChar());
#else
return AsString().mb_str();
#endif
}
-inline const wxWCharBuffer wxCStrData::AsWCharBuf() const
+inline const wxScopedWCharBuffer wxCStrData::AsWCharBuf() const
{
#if wxUSE_UNICODE_WCHAR
- return wxWCharBuffer::CreateNonOwned(AsWChar());
+ return wxScopedWCharBuffer::CreateNonOwned(AsWChar());
#else
return AsString().wc_str();
#endif
{
public:
wxFormatString(const char *str)
- : m_char(wxCharBuffer::CreateNonOwned(str)), m_str(NULL), m_cstr(NULL) {}
+ : m_char(wxScopedCharBuffer::CreateNonOwned(str)), m_str(NULL), m_cstr(NULL) {}
wxFormatString(const wchar_t *str)
- : m_wchar(wxWCharBuffer::CreateNonOwned(str)), m_str(NULL), m_cstr(NULL) {}
+ : m_wchar(wxScopedWCharBuffer::CreateNonOwned(str)), m_str(NULL), m_cstr(NULL) {}
wxFormatString(const wxString& str)
: m_str(&str), m_cstr(NULL) {}
wxFormatString(const wxCStrData& str)
: m_str(NULL), m_cstr(&str) {}
- wxFormatString(const wxCharBuffer& str)
+ wxFormatString(const wxScopedCharBuffer& str)
: m_char(str), m_str(NULL), m_cstr(NULL) {}
- wxFormatString(const wxWCharBuffer& str)
+ wxFormatString(const wxScopedWCharBuffer& str)
: m_wchar(str), m_str(NULL), m_cstr(NULL) {}
// ..AsWChar() below)
const char* InputAsChar();
const char* AsChar();
- wxCharBuffer m_convertedChar;
+ wxScopedCharBuffer m_convertedChar;
#endif // !wxUSE_UNICODE_WCHAR
#if wxUSE_UNICODE && !wxUSE_UTF8_LOCALE_ONLY
private:
const wchar_t* InputAsWChar();
const wchar_t* AsWChar();
- wxWCharBuffer m_convertedWChar;
+ wxScopedWCharBuffer m_convertedWChar;
#endif // wxUSE_UNICODE && !wxUSE_UTF8_LOCALE_ONLY
private:
- wxCharBuffer m_char;
- wxWCharBuffer m_wchar;
+ wxScopedCharBuffer m_char;
+ wxScopedWCharBuffer m_wchar;
// NB: we can use a pointer here, because wxFormatString is only used
// as function argument, so it has shorter life than the string
: public wxFormatStringArgumentFinder<const wxString&> {};
template<>
-struct wxFormatStringArgumentFinder<wxCharBuffer>
- : public wxFormatStringArgumentFinder<const wxCharBuffer&> {};
+struct wxFormatStringArgumentFinder<wxScopedCharBuffer>
+ : public wxFormatStringArgumentFinder<const wxScopedCharBuffer&> {};
template<>
-struct wxFormatStringArgumentFinder<wxWCharBuffer>
- : public wxFormatStringArgumentFinder<const wxWCharBuffer&> {};
+struct wxFormatStringArgumentFinder<wxScopedWCharBuffer>
+ : public wxFormatStringArgumentFinder<const wxScopedWCharBuffer&> {};
// ----------------------------------------------------------------------------
template<typename CharType>
struct wxArgNormalizerWithBuffer
{
- typedef wxCharTypeBuffer<CharType> CharBuffer;
+ typedef wxScopedCharTypeBuffer<CharType> CharBuffer;
wxArgNormalizerWithBuffer() {}
wxArgNormalizerWithBuffer(const CharBuffer& buf,
{
if ( wxLocaleIsUtf8 )
{
- m_value = wxCharBuffer::CreateNonOwned(s);
+ m_value = wxScopedCharBuffer::CreateNonOwned(s);
}
else
{
// convert to widechar string first:
- wxWCharBuffer buf(wxConvLibc.cMB2WC(s));
+ wxScopedWCharBuffer buf(wxConvLibc.cMB2WC(s));
// then to UTF-8:
if ( buf )
WX_ARG_NORMALIZER_FORWARD(wchar_t*, const wchar_t*);
// versions for passing wx[W]CharBuffer:
-WX_ARG_NORMALIZER_FORWARD(wxCharBuffer, const char*);
-WX_ARG_NORMALIZER_FORWARD(const wxCharBuffer&, const char*);
-WX_ARG_NORMALIZER_FORWARD(wxWCharBuffer, const wchar_t*);
-WX_ARG_NORMALIZER_FORWARD(const wxWCharBuffer&, const wchar_t*);
+WX_ARG_NORMALIZER_FORWARD(wxScopedCharBuffer, const char*);
+WX_ARG_NORMALIZER_FORWARD(const wxScopedCharBuffer&, const char*);
+WX_ARG_NORMALIZER_FORWARD(wxScopedWCharBuffer, const wchar_t*);
+WX_ARG_NORMALIZER_FORWARD(const wxScopedWCharBuffer&, const wchar_t*);
// versions for std::[w]string:
#if wxUSE_STD_STRING
#if SIZEOF_WCHAR_T == 2
typedef wxWCharBuffer wxU16CharBuffer;
+typedef wxScopedWCharBuffer wxScopedU16CharBuffer;
#else
typedef wxCharTypeBuffer<wxChar16> wxU16CharBuffer;
+typedef wxScopedCharTypeBuffer<wxChar16> wxScopedU16CharBuffer;
#endif
#if SIZEOF_WCHAR_T == 4
typedef wxWCharBuffer wxU32CharBuffer;
+typedef wxScopedWCharBuffer wxScopedU32CharBuffer;
#else
typedef wxCharTypeBuffer<wxChar32> wxU32CharBuffer;
+typedef wxScopedCharTypeBuffer<wxChar32> wxScopedU32CharBuffer;
#endif
wxUString( const wxChar32 *str ) { assign(str); }
wxUString( const wxUString &str ) { assign(str); }
- wxUString( const wxU32CharBuffer &buf ) { assign(buf); }
+ wxUString( const wxScopedU32CharBuffer &buf ) { assign(buf); }
wxUString( const char *str ) { assign(str); }
- wxUString( const wxCharBuffer &buf ) { assign(buf); }
+ wxUString( const wxScopedCharBuffer &buf ) { assign(buf); }
wxUString( const char *str, const wxMBConv &conv ) { assign(str,conv); }
- wxUString( const wxCharBuffer &buf, const wxMBConv &conv ) { assign(buf,conv); }
+ wxUString( const wxScopedCharBuffer &buf, const wxMBConv &conv ) { assign(buf,conv); }
wxUString( const wxChar16 *str ) { assign(str); }
- wxUString( const wxU16CharBuffer &buf ) { assign(buf); }
+ wxUString( const wxScopedU16CharBuffer &buf ) { assign(buf); }
wxUString( const wxCStrData *cstr ) { assign(cstr); }
wxUString( const wxString &str ) { assign(str); }
// conversions
- wxCharBuffer utf8_str() const;
- wxU16CharBuffer utf16_str() const;
+ wxScopedCharBuffer utf8_str() const;
+ wxScopedU16CharBuffer utf16_str() const;
#if SIZEOF_WCHAR_T == 2
- wxWCharBuffer wc_str() const
+ wxScopedWCharBuffer wc_str() const
{
return utf16_str();
}
}
#if wxUSE_UNICODE_UTF8
- wxCharBuffer wx_str()
+ wxScopedCharBuffer wx_str()
{
return utf8_str();
}
#else
#if SIZEOF_WCHAR_T == 2
- wxWCharBuffer wx_str()
+ wxScopedWCharBuffer wx_str()
{
return utf16_str();
}
return (wxUString &) base->assign( n, ch );
}
- wxUString &assign( const wxU32CharBuffer &buf )
+ wxUString &assign( const wxScopedU32CharBuffer &buf )
{
return assign( buf.data() );
}
return assignFromCString( str );
}
- wxUString &assign( const wxCharBuffer &buf )
+ wxUString &assign( const wxScopedCharBuffer &buf )
{
return assignFromCString( buf.data() );
}
return assignFromCString( str, conv );
}
- wxUString &assign( const wxCharBuffer &buf, const wxMBConv &conv )
+ wxUString &assign( const wxScopedCharBuffer &buf, const wxMBConv &conv )
{
return assignFromCString( buf.data(), conv );
}
return assignFromUTF16( str );
}
- wxUString &assign( const wxU16CharBuffer &buf )
+ wxUString &assign( const wxScopedU16CharBuffer &buf )
{
return assignFromUTF16( buf.data() );
}
// append [wx overload]
- wxUString &append( const wxU16CharBuffer &buf )
+ wxUString &append( const wxScopedU16CharBuffer &buf )
{
return append( buf.data() );
}
- wxUString &append( const wxU32CharBuffer &buf )
+ wxUString &append( const wxScopedU32CharBuffer &buf )
{
return append( buf.data() );
}
return append( wxUString( str ) );
}
- wxUString &append( const wxCharBuffer &buf )
+ wxUString &append( const wxScopedCharBuffer &buf )
{
return append( wxUString( buf ) );
}
return insert( n, wxUString( s ) );
}
- wxUString &insert( size_type n, const wxCharBuffer &buf )
+ wxUString &insert( size_type n, const wxScopedCharBuffer &buf )
{
return insert( n, wxUString( buf ) );
}
- wxUString &insert( size_type n, const wxU16CharBuffer &buf )
+ wxUString &insert( size_type n, const wxScopedU16CharBuffer &buf )
{
return insert( n, wxUString( buf ) );
}
- wxUString &insert( size_type n, const wxU32CharBuffer &buf )
+ wxUString &insert( size_type n, const wxScopedU32CharBuffer &buf )
{
return insert( n, buf.data() );
}
{ return assign( s ); }
wxUString& operator=(const wxChar32 *s)
{ return assign( s ); }
- wxUString& operator=(const wxCharBuffer &s)
+ wxUString& operator=(const wxScopedCharBuffer &s)
{ return assign( s ); }
- wxUString& operator=(const wxU16CharBuffer &s)
+ wxUString& operator=(const wxScopedU16CharBuffer &s)
{ return assign( s ); }
- wxUString& operator=(const wxU32CharBuffer &s)
+ wxUString& operator=(const wxScopedU32CharBuffer &s)
{ return assign( s ); }
wxUString& operator=(const char ch)
{ return assign( ch ); }
{ return append( s ); }
wxUString& operator+=(const wxChar32 *s)
{ return append( s ); }
- wxUString& operator+=(const wxCharBuffer &s)
+ wxUString& operator+=(const wxScopedCharBuffer &s)
{ return append( s ); }
- wxUString& operator+=(const wxU16CharBuffer &s)
+ wxUString& operator+=(const wxScopedU16CharBuffer &s)
{ return append( s ); }
- wxUString& operator+=(const wxU32CharBuffer &s)
+ wxUString& operator+=(const wxScopedU32CharBuffer &s)
{ return append( s ); }
wxUString& operator+=(const char ch)
{ return append( ch ); }
{ return s1 + wxUString(s2); }
inline wxUString operator+(const wxUString &s1, const wxChar32 *s2)
{ return s1 + wxUString(s2); }
-inline wxUString operator+(const wxUString &s1, const wxCharBuffer &s2)
+inline wxUString operator+(const wxUString &s1, const wxScopedCharBuffer &s2)
{ return s1 + wxUString(s2); }
-inline wxUString operator+(const wxUString &s1, const wxU16CharBuffer &s2)
+inline wxUString operator+(const wxUString &s1, const wxScopedU16CharBuffer &s2)
{ return s1 + wxUString(s2); }
-inline wxUString operator+(const wxUString &s1, const wxU32CharBuffer &s2)
+inline wxUString operator+(const wxUString &s1, const wxScopedU32CharBuffer &s2)
{ return s1 + wxUString(s2); }
inline wxUString operator+(const wxUString &s1, char s2)
{ return s1 + wxUString(s2); }
{ return wxUString(s1) + s2; }
inline wxUString operator+(const wxChar32 *s1, const wxUString &s2)
{ return wxUString(s1) + s2; }
-inline wxUString operator+(const wxCharBuffer &s1, const wxUString &s2)
+inline wxUString operator+(const wxScopedCharBuffer &s1, const wxUString &s2)
{ return wxUString(s1) + s2; }
-inline wxUString operator+(const wxU16CharBuffer &s1, const wxUString &s2)
+inline wxUString operator+(const wxScopedU16CharBuffer &s1, const wxUString &s2)
{ return wxUString(s1) + s2; }
-inline wxUString operator+(const wxU32CharBuffer &s1, const wxUString &s2)
+inline wxUString operator+(const wxScopedU32CharBuffer &s1, const wxUString &s2)
{ return wxUString(s1) + s2; }
inline wxUString operator+(char s1, const wxUString &s2)
{ return wxUString(s1) + s2; }
wxUSTRING_COMP_OPERATORS( const char * )
wxUSTRING_COMP_OPERATORS( const wxChar16 * )
wxUSTRING_COMP_OPERATORS( const wxChar32 * )
-wxUSTRING_COMP_OPERATORS( const wxCharBuffer & )
-wxUSTRING_COMP_OPERATORS( const wxU16CharBuffer & )
-wxUSTRING_COMP_OPERATORS( const wxU32CharBuffer & )
+wxUSTRING_COMP_OPERATORS( const wxScopedCharBuffer & )
+wxUSTRING_COMP_OPERATORS( const wxScopedU16CharBuffer & )
+wxUSTRING_COMP_OPERATORS( const wxScopedU32CharBuffer & )
wxUSTRING_COMP_OPERATORS( const wxCStrData * )
#endif // _WX_USTRING_H_
inline bool wxSetEnv(const wxString& var, const wchar_t *value)
{ return wxSetEnv(var, wxString(value)); }
template<typename T>
-inline bool wxSetEnv(const wxString& var, const wxCharTypeBuffer<T>& value)
+inline bool wxSetEnv(const wxString& var, const wxScopedCharTypeBuffer<T>& value)
{ return wxSetEnv(var, wxString(value)); }
inline bool wxSetEnv(const wxString& var, const wxCStrData& value)
{ return wxSetEnv(var, wxString(value)); }
wxVariant(const char* val, const wxString& name = wxEmptyString);
wxVariant(const wchar_t* val, const wxString& name = wxEmptyString);
wxVariant(const wxCStrData& val, const wxString& name = wxEmptyString);
- wxVariant(const wxCharBuffer& val, const wxString& name = wxEmptyString);
- wxVariant(const wxWCharBuffer& val, const wxString& name = wxEmptyString);
+ wxVariant(const wxScopedCharBuffer& val, const wxString& name = wxEmptyString);
+ wxVariant(const wxScopedWCharBuffer& val, const wxString& name = wxEmptyString);
bool operator== (const wxString& value) const;
bool operator!= (const wxString& value) const;
wxVariant& operator=(const wxCStrData& value)
{ return *this = value.AsString(); }
template<typename T>
- wxVariant& operator=(const wxCharTypeBuffer<T>& value)
+ wxVariant& operator=(const wxScopedCharTypeBuffer<T>& value)
{ return *this = value.data(); }
inline operator wxString () const { return MakeString(); }
/* checks whether the passed in pointer is NULL and if the string is empty */
inline bool wxIsEmpty(const char *s) { return !s || !*s; }
inline bool wxIsEmpty(const wchar_t *s) { return !s || !*s; }
-inline bool wxIsEmpty(const wxCharBuffer& s) { return wxIsEmpty(s.data()); }
-inline bool wxIsEmpty(const wxWCharBuffer& s) { return wxIsEmpty(s.data()); }
+inline bool wxIsEmpty(const wxScopedCharBuffer& s) { return wxIsEmpty(s.data()); }
+inline bool wxIsEmpty(const wxScopedWCharBuffer& s) { return wxIsEmpty(s.data()); }
inline bool wxIsEmpty(const wxString& s) { return s.empty(); }
inline bool wxIsEmpty(const wxCStrData& s) { return s.AsString().empty(); }
// wxSetlocale(category, NULL) -- which is a common thing to do -- would be
// ambiguous
WXDLLIMPEXP_BASE char* wxSetlocale(int category, const char *locale);
-inline char* wxSetlocale(int category, const wxCharBuffer& locale)
+inline char* wxSetlocale(int category, const wxScopedCharBuffer& locale)
{ return wxSetlocale(category, locale.data()); }
inline char* wxSetlocale(int category, const wxString& locale)
{ return wxSetlocale(category, locale.mb_str()); }
// NB: these are defined in wxcrtbase.h, see the comment there
// inline size_t wxStrlen(const char *s) { return s ? strlen(s) : 0; }
// inline size_t wxStrlen(const wchar_t *s) { return s ? wxCRT_Strlen_(s) : 0; }
-inline size_t wxStrlen(const wxCharBuffer& s) { return wxStrlen(s.data()); }
-inline size_t wxStrlen(const wxWCharBuffer& s) { return wxStrlen(s.data()); }
+inline size_t wxStrlen(const wxScopedCharBuffer& s) { return wxStrlen(s.data()); }
+inline size_t wxStrlen(const wxScopedWCharBuffer& s) { return wxStrlen(s.data()); }
inline size_t wxStrlen(const wxString& s) { return s.length(); }
inline size_t wxStrlen(const wxCStrData& s) { return s.AsString().length(); }
// this is a function new in 2.9 so we don't care about backwards compatibility and
-// so don't need to support wxCharBuffer/wxWCharBuffer overloads
+// so don't need to support wxScopedCharBuffer/wxScopedWCharBuffer overloads
#if defined(wxCRT_StrnlenA)
inline size_t wxStrnlen(const char *str, size_t maxlen) { return wxCRT_StrnlenA(str, maxlen); }
#else
// NB: these are defined in wxcrtbase.h, see the comment there
// inline char* wxStrdup(const char *s) { return wxStrdupA(s); }
// inline wchar_t* wxStrdup(const wchar_t *s) { return wxStrdupW(s); }
-inline char* wxStrdup(const wxCharBuffer& s) { return wxStrdup(s.data()); }
-inline wchar_t* wxStrdup(const wxWCharBuffer& s) { return wxStrdup(s.data()); }
+inline char* wxStrdup(const wxScopedCharBuffer& s) { return wxStrdup(s.data()); }
+inline wchar_t* wxStrdup(const wxScopedWCharBuffer& s) { return wxStrdup(s.data()); }
inline char* wxStrdup(const wxString& s) { return wxStrdup(s.mb_str()); }
inline char* wxStrdup(const wxCStrData& s) { return wxStrdup(s.AsCharBuf()); }
{ return wxCRT_StrcpyA(dest, src.mb_str()); }
inline char *wxStrcpy(char *dest, const wxCStrData& src)
{ return wxCRT_StrcpyA(dest, src.AsCharBuf()); }
-inline char *wxStrcpy(char *dest, const wxCharBuffer& src)
+inline char *wxStrcpy(char *dest, const wxScopedCharBuffer& src)
{ return wxCRT_StrcpyA(dest, src.data()); }
inline wchar_t *wxStrcpy(wchar_t *dest, const wxString& src)
{ return wxCRT_StrcpyW(dest, src.wc_str()); }
inline wchar_t *wxStrcpy(wchar_t *dest, const wxCStrData& src)
{ return wxCRT_StrcpyW(dest, src.AsWCharBuf()); }
-inline wchar_t *wxStrcpy(wchar_t *dest, const wxWCharBuffer& src)
+inline wchar_t *wxStrcpy(wchar_t *dest, const wxScopedWCharBuffer& src)
{ return wxCRT_StrcpyW(dest, src.data()); }
inline char *wxStrcpy(char *dest, const wchar_t *src)
{ return wxCRT_StrcpyA(dest, wxConvLibc.cWC2MB(src)); }
{ return wxCRT_StrncpyA(dest, src.mb_str(), n); }
inline char *wxStrncpy(char *dest, const wxCStrData& src, size_t n)
{ return wxCRT_StrncpyA(dest, src.AsCharBuf(), n); }
-inline char *wxStrncpy(char *dest, const wxCharBuffer& src, size_t n)
+inline char *wxStrncpy(char *dest, const wxScopedCharBuffer& src, size_t n)
{ return wxCRT_StrncpyA(dest, src.data(), n); }
inline wchar_t *wxStrncpy(wchar_t *dest, const wxString& src, size_t n)
{ return wxCRT_StrncpyW(dest, src.wc_str(), n); }
inline wchar_t *wxStrncpy(wchar_t *dest, const wxCStrData& src, size_t n)
{ return wxCRT_StrncpyW(dest, src.AsWCharBuf(), n); }
-inline wchar_t *wxStrncpy(wchar_t *dest, const wxWCharBuffer& src, size_t n)
+inline wchar_t *wxStrncpy(wchar_t *dest, const wxScopedWCharBuffer& src, size_t n)
{ return wxCRT_StrncpyW(dest, src.data(), n); }
inline char *wxStrncpy(char *dest, const wchar_t *src, size_t n)
{ return wxCRT_StrncpyA(dest, wxConvLibc.cWC2MB(src), n); }
{ return wxCRT_StrcatA(dest, src.mb_str()); }
inline char *wxStrcat(char *dest, const wxCStrData& src)
{ return wxCRT_StrcatA(dest, src.AsCharBuf()); }
-inline char *wxStrcat(char *dest, const wxCharBuffer& src)
+inline char *wxStrcat(char *dest, const wxScopedCharBuffer& src)
{ return wxCRT_StrcatA(dest, src.data()); }
inline wchar_t *wxStrcat(wchar_t *dest, const wxString& src)
{ return wxCRT_StrcatW(dest, src.wc_str()); }
inline wchar_t *wxStrcat(wchar_t *dest, const wxCStrData& src)
{ return wxCRT_StrcatW(dest, src.AsWCharBuf()); }
-inline wchar_t *wxStrcat(wchar_t *dest, const wxWCharBuffer& src)
+inline wchar_t *wxStrcat(wchar_t *dest, const wxScopedWCharBuffer& src)
{ return wxCRT_StrcatW(dest, src.data()); }
inline char *wxStrcat(char *dest, const wchar_t *src)
{ return wxCRT_StrcatA(dest, wxConvLibc.cWC2MB(src)); }
{ return wxCRT_StrncatA(dest, src.mb_str(), n); }
inline char *wxStrncat(char *dest, const wxCStrData& src, size_t n)
{ return wxCRT_StrncatA(dest, src.AsCharBuf(), n); }
-inline char *wxStrncat(char *dest, const wxCharBuffer& src, size_t n)
+inline char *wxStrncat(char *dest, const wxScopedCharBuffer& src, size_t n)
{ return wxCRT_StrncatA(dest, src.data(), n); }
inline wchar_t *wxStrncat(wchar_t *dest, const wxString& src, size_t n)
{ return wxCRT_StrncatW(dest, src.wc_str(), n); }
inline wchar_t *wxStrncat(wchar_t *dest, const wxCStrData& src, size_t n)
{ return wxCRT_StrncatW(dest, src.AsWCharBuf(), n); }
-inline wchar_t *wxStrncat(wchar_t *dest, const wxWCharBuffer& src, size_t n)
+inline wchar_t *wxStrncat(wchar_t *dest, const wxScopedWCharBuffer& src, size_t n)
{ return wxCRT_StrncatW(dest, src.data(), n); }
inline char *wxStrncat(char *dest, const wchar_t *src, size_t n)
{ return wxCRT_StrncatA(dest, wxConvLibc.cWC2MB(src), n); }
{ return WX_STR_CALL(crtA, s1, s2); } \
inline rettype WX_STR_DECL(name, const char *, const wchar_t *) \
{ return WX_STR_CALL(forString, wxString(s1), wxString(s2)); } \
- inline rettype WX_STR_DECL(name, const char *, const wxCharBuffer&) \
+ inline rettype WX_STR_DECL(name, const char *, const wxScopedCharBuffer&) \
{ return WX_STR_CALL(crtA, s1, s2.data()); } \
- inline rettype WX_STR_DECL(name, const char *, const wxWCharBuffer&) \
+ inline rettype WX_STR_DECL(name, const char *, const wxScopedWCharBuffer&) \
{ return WX_STR_CALL(forString, wxString(s1), s2.data()); } \
\
inline rettype WX_STR_DECL(name, const wchar_t *, const wchar_t *) \
{ return WX_STR_CALL(crtW, s1, s2); } \
inline rettype WX_STR_DECL(name, const wchar_t *, const char *) \
{ return WX_STR_CALL(forString, wxString(s1), wxString(s2)); } \
- inline rettype WX_STR_DECL(name, const wchar_t *, const wxWCharBuffer&) \
+ inline rettype WX_STR_DECL(name, const wchar_t *, const wxScopedWCharBuffer&) \
{ return WX_STR_CALL(crtW, s1, s2.data()); } \
- inline rettype WX_STR_DECL(name, const wchar_t *, const wxCharBuffer&) \
+ inline rettype WX_STR_DECL(name, const wchar_t *, const wxScopedCharBuffer&) \
{ return WX_STR_CALL(forString, wxString(s1), s2.data()); } \
\
- inline rettype WX_STR_DECL(name, const wxCharBuffer&, const char *) \
+ inline rettype WX_STR_DECL(name, const wxScopedCharBuffer&, const char *) \
{ return WX_STR_CALL(crtA, s1.data(), s2); } \
- inline rettype WX_STR_DECL(name, const wxCharBuffer&, const wchar_t *) \
+ inline rettype WX_STR_DECL(name, const wxScopedCharBuffer&, const wchar_t *) \
{ return WX_STR_CALL(forString, wxString(s1), wxString(s2)); } \
- inline rettype WX_STR_DECL(name, const wxCharBuffer&, const wxCharBuffer&)\
+ inline rettype WX_STR_DECL(name, const wxScopedCharBuffer&, const wxScopedCharBuffer&)\
{ return WX_STR_CALL(crtA, s1.data(), s2.data()); } \
- inline rettype WX_STR_DECL(name, const wxCharBuffer&, const wxWCharBuffer&) \
+ inline rettype WX_STR_DECL(name, const wxScopedCharBuffer&, const wxScopedWCharBuffer&) \
{ return WX_STR_CALL(forString, wxString(s1), wxString(s2)); } \
\
- inline rettype WX_STR_DECL(name, const wxWCharBuffer&, const wchar_t *) \
+ inline rettype WX_STR_DECL(name, const wxScopedWCharBuffer&, const wchar_t *) \
{ return WX_STR_CALL(crtW, s1.data(), s2); } \
- inline rettype WX_STR_DECL(name, const wxWCharBuffer&, const char *) \
+ inline rettype WX_STR_DECL(name, const wxScopedWCharBuffer&, const char *) \
{ return WX_STR_CALL(forString, wxString(s1), wxString(s2)); } \
- inline rettype WX_STR_DECL(name, const wxWCharBuffer&, const wxWCharBuffer&) \
+ inline rettype WX_STR_DECL(name, const wxScopedWCharBuffer&, const wxScopedWCharBuffer&) \
{ return WX_STR_CALL(crtW, s1.data(), s2.data()); } \
- inline rettype WX_STR_DECL(name, const wxWCharBuffer&, const wxCharBuffer&) \
+ inline rettype WX_STR_DECL(name, const wxScopedWCharBuffer&, const wxScopedCharBuffer&) \
{ return WX_STR_CALL(forString, wxString(s1), wxString(s2)); } \
\
inline rettype WX_STR_DECL(name, const wxString&, const char*) \
{ return WX_STR_CALL(forString, s1, s2); } \
inline rettype WX_STR_DECL(name, const wxString&, const wchar_t*) \
{ return WX_STR_CALL(forString, s1, s2); } \
- inline rettype WX_STR_DECL(name, const wxString&, const wxCharBuffer&) \
+ inline rettype WX_STR_DECL(name, const wxString&, const wxScopedCharBuffer&) \
{ return WX_STR_CALL(forString, s1, s2); } \
- inline rettype WX_STR_DECL(name, const wxString&, const wxWCharBuffer&) \
+ inline rettype WX_STR_DECL(name, const wxString&, const wxScopedWCharBuffer&) \
{ return WX_STR_CALL(forString, s1, s2); } \
inline rettype WX_STR_DECL(name, const wxString&, const wxString&) \
{ return WX_STR_CALL(forString, s1, s2); } \
{ return WX_STR_CALL(forString, s1.AsString(), s2); } \
inline rettype WX_STR_DECL(name, const wxCStrData&, const wchar_t*) \
{ return WX_STR_CALL(forString, s1.AsString(), s2); } \
- inline rettype WX_STR_DECL(name, const wxCStrData&, const wxCharBuffer&) \
+ inline rettype WX_STR_DECL(name, const wxCStrData&, const wxScopedCharBuffer&) \
{ return WX_STR_CALL(forString, s1.AsString(), s2); } \
- inline rettype WX_STR_DECL(name, const wxCStrData&, const wxWCharBuffer&) \
+ inline rettype WX_STR_DECL(name, const wxCStrData&, const wxScopedWCharBuffer&) \
{ return WX_STR_CALL(forString, s1.AsString(), s2); } \
inline rettype WX_STR_DECL(name, const wxCStrData&, const wxString&) \
{ return WX_STR_CALL(forString, s1.AsString(), s2); } \
inline int WX_STR_DECL(name, const wchar_t *, const wxString&) \
{ return -WX_STR_CALL(forString, s2, s1); } \
\
- inline int WX_STR_DECL(name, const wxCharBuffer&, const wxCStrData&) \
+ inline int WX_STR_DECL(name, const wxScopedCharBuffer&, const wxCStrData&) \
{ return -WX_STR_CALL(forString, s2.AsString(), s1.data()); } \
- inline int WX_STR_DECL(name, const wxCharBuffer&, const wxString&) \
+ inline int WX_STR_DECL(name, const wxScopedCharBuffer&, const wxString&) \
{ return -WX_STR_CALL(forString, s2, s1.data()); } \
\
- inline int WX_STR_DECL(name, const wxWCharBuffer&, const wxCStrData&) \
+ inline int WX_STR_DECL(name, const wxScopedWCharBuffer&, const wxCStrData&) \
{ return -WX_STR_CALL(forString, s2.AsString(), s1.data()); } \
- inline int WX_STR_DECL(name, const wxWCharBuffer&, const wxString&) \
+ inline int WX_STR_DECL(name, const wxScopedWCharBuffer&, const wxString&) \
{ return -WX_STR_CALL(forString, s2, s1.data()); }
inline rettype WX_STR_DECL(name, const wchar_t *, const wxString&) \
{ return WX_STR_CALL(crtW, s1, s2.wc_str()); } \
\
- inline rettype WX_STR_DECL(name, const wxCharBuffer&, const wxCStrData&) \
+ inline rettype WX_STR_DECL(name, const wxScopedCharBuffer&, const wxCStrData&) \
{ return WX_STR_CALL(crtA, s1.data(), s2.AsCharBuf()); } \
- inline rettype WX_STR_DECL(name, const wxCharBuffer&, const wxString&) \
+ inline rettype WX_STR_DECL(name, const wxScopedCharBuffer&, const wxString&) \
{ return WX_STR_CALL(crtA, s1.data(), s2.mb_str()); } \
\
- inline rettype WX_STR_DECL(name, const wxWCharBuffer&, const wxCStrData&) \
+ inline rettype WX_STR_DECL(name, const wxScopedWCharBuffer&, const wxCStrData&) \
{ return WX_STR_CALL(crtW, s1.data(), s2.AsWCharBuf()); } \
- inline rettype WX_STR_DECL(name, const wxWCharBuffer&, const wxString&) \
+ inline rettype WX_STR_DECL(name, const wxScopedWCharBuffer&, const wxString&) \
{ return WX_STR_CALL(crtW, s1.data(), s2.wc_str()); }
template<typename T>
// NB: strcoll() doesn't work correctly on UTF-8 strings, so we have to use
// wc_str() even if wxUSE_UNICODE_UTF8; the (const wchar_t*) cast is
// there just as optimization to avoid going through
- // wxStrcoll<wxWCharBuffer>:
+ // wxStrcoll<wxScopedWCharBuffer>:
return wxStrcoll((const wchar_t*)s1.wc_str(), s2);
#else
return wxStrcoll((const char*)s1.mb_str(), s2);
inline size_t wxStrxfrm(wchar_t *dest, const wchar_t *src, size_t n)
{ return wxCRT_StrxfrmW(dest, src, n); }
template<typename T>
-inline size_t wxStrxfrm(T *dest, const wxCharTypeBuffer<T>& src, size_t n)
+inline size_t wxStrxfrm(T *dest, const wxScopedCharTypeBuffer<T>& src, size_t n)
{ return wxStrxfrm(dest, src.data(), n); }
inline size_t wxStrxfrm(char *dest, const wxString& src, size_t n)
{ return wxCRT_StrxfrmA(dest, src.mb_str(), n); }
inline wchar_t *wxStrtok(wchar_t *str, const wchar_t *delim, wchar_t **saveptr)
{ return wxCRT_StrtokW(str, delim, saveptr); }
template<typename T>
-inline T *wxStrtok(T *str, const wxCharTypeBuffer<T>& delim, T **saveptr)
+inline T *wxStrtok(T *str, const wxScopedCharTypeBuffer<T>& delim, T **saveptr)
{ return wxStrtok(str, delim.data(), saveptr); }
inline char *wxStrtok(char *str, const wxCStrData& delim, char **saveptr)
{ return wxCRT_StrtokA(str, delim.AsCharBuf(), saveptr); }
inline const wchar_t *wxStrrchr(const wchar_t *s, const wxUniCharRef& c)
{ return wxCRT_StrrchrW(s, (wchar_t)c); }
template<typename T>
-inline const T* wxStrchr(const wxCharTypeBuffer<T>& s, T c)
+inline const T* wxStrchr(const wxScopedCharTypeBuffer<T>& s, T c)
{ return wxStrchr(s.data(), c); }
template<typename T>
-inline const T* wxStrrchr(const wxCharTypeBuffer<T>& s, T c)
+inline const T* wxStrrchr(const wxScopedCharTypeBuffer<T>& s, T c)
{ return wxStrrchr(s.data(), c); }
template<typename T>
-inline const T* wxStrchr(const wxCharTypeBuffer<T>& s, const wxUniChar& c)
+inline const T* wxStrchr(const wxScopedCharTypeBuffer<T>& s, const wxUniChar& c)
{ return wxStrchr(s.data(), (T)c); }
template<typename T>
-inline const T* wxStrrchr(const wxCharTypeBuffer<T>& s, const wxUniChar& c)
+inline const T* wxStrrchr(const wxScopedCharTypeBuffer<T>& s, const wxUniChar& c)
{ return wxStrrchr(s.data(), (T)c); }
template<typename T>
-inline const T* wxStrchr(const wxCharTypeBuffer<T>& s, const wxUniCharRef& c)
+inline const T* wxStrchr(const wxScopedCharTypeBuffer<T>& s, const wxUniCharRef& c)
{ return wxStrchr(s.data(), (T)c); }
template<typename T>
-inline const T* wxStrrchr(const wxCharTypeBuffer<T>& s, const wxUniCharRef& c)
+inline const T* wxStrrchr(const wxScopedCharTypeBuffer<T>& s, const wxUniCharRef& c)
{ return wxStrrchr(s.data(), (T)c); }
// these functions return char* pointer into the non-temporary conversion buffer
// used by c_str()'s implicit conversion to char*, for ANSI build compatibility
inline const char *wxStrpbrk(const wxCStrData& s, const wxCStrData& accept)
{ return wxCRT_StrpbrkA(s.AsChar(), accept.AsCharBuf()); }
template <typename S, typename T>
-inline const T *wxStrpbrk(const S& s, const wxCharTypeBuffer<T>& accept)
+inline const T *wxStrpbrk(const S& s, const wxScopedCharTypeBuffer<T>& accept)
{ return wxStrpbrk(s, accept.data()); }
inline double wxStrtod(const wchar_t *nptr, wchar_t **endptr)
{ return wxCRT_StrtodW(nptr, endptr); }
template<typename T>
-inline double wxStrtod(const wxCharTypeBuffer<T>& nptr, T **endptr)
+inline double wxStrtod(const wxScopedCharTypeBuffer<T>& nptr, T **endptr)
{ return wxStrtod(nptr.data(), endptr); }
// We implement wxStrto*() like this so that the code compiles when NULL is
inline rettype name(const wchar_t *nptr, wchar_t **endptr, int base) \
{ return implW(nptr, endptr, base); } \
template<typename T> \
- inline rettype name(const wxCharTypeBuffer<T>& nptr, T **endptr, int base)\
+ inline rettype name(const wxScopedCharTypeBuffer<T>& nptr, T **endptr, int base)\
{ return name(nptr.data(), endptr); } \
template<typename T> \
inline rettype name(const wxString& nptr, T endptr, int base) \
inline wchar_t* wxGetenv(const wchar_t *name) { return wxCRT_GetenvW(name); }
inline char* wxGetenv(const wxString& name) { return wxCRT_GetenvA(name.mb_str()); }
inline char* wxGetenv(const wxCStrData& name) { return wxCRT_GetenvA(name.AsCharBuf()); }
-inline char* wxGetenv(const wxCharBuffer& name) { return wxCRT_GetenvA(name.data()); }
-inline wchar_t* wxGetenv(const wxWCharBuffer& name) { return wxCRT_GetenvW(name.data()); }
+inline char* wxGetenv(const wxScopedCharBuffer& name) { return wxCRT_GetenvA(name.data()); }
+inline wchar_t* wxGetenv(const wxScopedWCharBuffer& name) { return wxCRT_GetenvW(name.data()); }
// ----------------------------------------------------------------------------
// time.h functions
#ifdef __WINDOWS__
#define wxScanfConvertFormatW(fmt) fmt
#else
- const wxWCharBuffer
+ const wxScopedWCharBuffer
WXDLLIMPEXP_BASE wxScanfConvertFormatW(const wchar_t *format);
#endif
wxCRT_SscanfA, (str, format))
WX_DEFINE_SCANFUNC(wxSscanf, 2, (const wchar_t *str, const wchar_t *format),
wxCRT_SscanfW, (str, wxScanfConvertFormatW(format)))
-WX_DEFINE_SCANFUNC(wxSscanf, 2, (const wxCharBuffer& str, const char *format),
+WX_DEFINE_SCANFUNC(wxSscanf, 2, (const wxScopedCharBuffer& str, const char *format),
wxCRT_SscanfA, (str.data(), format))
-WX_DEFINE_SCANFUNC(wxSscanf, 2, (const wxWCharBuffer& str, const wchar_t *format),
+WX_DEFINE_SCANFUNC(wxSscanf, 2, (const wxScopedWCharBuffer& str, const wchar_t *format),
wxCRT_SscanfW, (str.data(), wxScanfConvertFormatW(format)))
WX_DEFINE_SCANFUNC(wxSscanf, 2, (const wxString& str, const char *format),
wxCRT_SscanfA, (str.mb_str(), format))
#ifndef __VISUALC___
int WXDLLIMPEXP_BASE wxVsscanf(const char *str, const char *format, va_list ap);
int WXDLLIMPEXP_BASE wxVsscanf(const wchar_t *str, const wchar_t *format, va_list ap);
-int WXDLLIMPEXP_BASE wxVsscanf(const wxCharBuffer& str, const char *format, va_list ap);
-int WXDLLIMPEXP_BASE wxVsscanf(const wxWCharBuffer& str, const wchar_t *format, va_list ap);
+int WXDLLIMPEXP_BASE wxVsscanf(const wxScopedCharBuffer& str, const char *format, va_list ap);
+int WXDLLIMPEXP_BASE wxVsscanf(const wxScopedWCharBuffer& str, const wchar_t *format, va_list ap);
int WXDLLIMPEXP_BASE wxVsscanf(const wxString& str, const char *format, va_list ap);
int WXDLLIMPEXP_BASE wxVsscanf(const wxString& str, const wchar_t *format, va_list ap);
int WXDLLIMPEXP_BASE wxVsscanf(const wxCStrData& str, const char *format, va_list ap);
/**
- wxCharTypeBuffer<T> is a template class for storing characters.
+ wxScopedCharTypeBuffer<T> is a template class for storing characters.
+
+ Data are stored in reference-counted buffer. In other words, making a copy
+ of wxScopedCharTypeBuffer<T> will @em not make another copy of the stored
+ string data, it will still point to the same location in memory.
+
+ wxScopedCharTypeBuffer<T> supports two storage modes: owned and non-owned.
+ "Owned" data buffer (created with CreateOwned() or wxCharTypeBuffer<T>
+ derived class) owns the data and frees them when the last buffer pointing
+ to them is destroyed.
+
+ "Non-owned" buffer (created with CreateNonOwned()), on the other hand,
+ references data owned by somebody else -- typical use is by
+ wxString::mb_str() or wxString::wc_str(), which may return non-owned buffer
+ pointing to wxString's internal store.
+
+ Because of this, the validity of data stored in wxScopedCharTypeBuffer<T>
+ is limited by the lifetime of the "parent" object that created the
+ buffer (e.g. the wxString on which mb_str() was called).
- @todo provide better docs for this class
+ If you need to preserve the data for longer, assign it to
+ wxCharTypeBuffer<T> instead of wxScopedCharTypeBuffer<T>. On the other
+ hand, use wxScopedCharTypeBuffer<T> if the buffer is to be destroyed before
+ the "parent" object -- typical use would be creating it on the stack and
+ destroying when it goes out of scope (hence the class' name).
@tparam T
The type of the characters stored in this class.
+ @since 2.9.0
+
@nolibrary
@category{data}
*/
template <typename T>
-class wxCharTypeBuffer
+class wxScopedCharTypeBuffer
{
public:
+ /// Stored characters type.
typedef T CharType;
+ /// Default constructor, creates NULL buffer.
+ wxScopedCharTypeBuffer();
+
+ /**
+ Creates non-owned buffer from string data @a str.
+
+ The buffer's destructor will not destroy @a str. The returned buffer's
+ data is valid only as long as @a str is valid.
+ */
+ static const wxScopedCharTypeBuffer CreateNonOwned(const CharType *str);
+
+ /**
+ Creates owned buffer from @a str and takes ownership of it.
+
+ The buffer's destructor will free @a str when its reference count
+ reaches zero (initial count is 1).
+ */
+ static const wxScopedCharTypeBuffer CreateOwned(const CharType *str);
+
+ /**
+ Copy constructor.
+
+ Increases reference count on the data, does @em not make wxStrdup()
+ copy of the data.
+ */
+ wxScopedCharTypeBuffer(const wxScopedCharTypeBuffer& src);
+
+ /// Assignment operator behaves in the same way as the copy constructor.
+ wxScopedCharTypeBuffer& operator=(const wxScopedCharTypeBuffer& src);
+
+ /**
+ Destructor. Frees stored data if it is in "owned" mode and data's
+ reference count reaches zero.
+ */
+ ~wxScopedCharTypeBuffer();
+
+ /// Resets the buffer to NULL, freeing the data if necessary.
+ void reset();
+
+ /// Returns pointer to the stored data.
+ CharType *data();
+
+ /// Returns const pointer to the stored data.
+ const CharType *data() const;
+
+ /// Implicit conversion to C string.
+ operator const CharType *() const;
+
+ /// Random access to the stored C string.
+ CharType operator[](size_t n) const;
+};
+
+/// Scoped char buffer.
+typedef wxScopedCharTypeBuffer<char> wxScopedCharBuffer;
+
+/// Scoped wchar_t buffer.
+typedef wxScopedCharTypeBuffer<wchar_t> wxScopedWCharBuffer;
+
+/**
+ wxCharTypeBuffer<T> is a template class for storing characters.
+
+ The difference from wxScopedCharTypeBuffer<T> is that this class
+ doesn't have non-owned mode and the data stored in it are valid for
+ as long as the buffer instance exists. Other than that, this class'
+ behaviour is the same as wxScopedCharTypeBuffer<T>'s -- in particular,
+ the data are reference-counted and copying the buffer is cheap.
+
+ wxScopedCharTypeBuffer<T> buffers can be converted into wxCharTypeBuffer<T>.
+
+ @tparam T
+ The type of the characters stored in this class.
+
+ @since 2.9.0
+
+ @nolibrary
+ @category{data}
+*/
+template <typename T>
+class wxCharTypeBuffer : public wxScopedCharTypeBuffer<T>
+{
+public:
+ /**
+ Creates (owned) buffer from @a str and takes ownership of it.
+
+ @see wxScopedCharTypeBuffer<T>::CreateOwned()
+ */
wxCharTypeBuffer(const CharType *str = NULL);
+
+
+ /**
+ Creates (owned) buffer of size @a len.
+
+ @see wxScopedCharTypeBuffer<T>::CreateOwned()
+ */
wxCharTypeBuffer(size_t len);
+
+ /**
+ Copy constructor.
+
+ Increases reference count on the data, does @em not make wxStrdup()
+ copy of the data.
+ */
wxCharTypeBuffer(const wxCharTypeBuffer& src);
- ~wxCharTypeBuffer();
- void reset();
+ /**
+ Makes a copy of scoped buffer @a src.
+
+ If @a src is a non-owned buffer, a copy of its data is made using
+ wxStrdup(). If @a src is an owned buffer, this constructor behaves
+ in the usual way (reference count on buffer data is incremented).
+ */
+ wxCharTypeBuffer(const wxScopedCharTypeBuffer<T>& src);
+ /**
+ Assigns @a str to this buffer and takes ownership of it (i.e. the
+ buffer becomes "owned").
+ */
wxCharTypeBuffer& operator=(const CharType *str);
+
+ /// Assignment operator behaves in the same way as the copy constructor.
wxCharTypeBuffer& operator=(const wxCharTypeBuffer& src);
- bool extend(size_t len);
+ /**
+ Assigns a scoped buffer to this buffer.
- CharType *data();
- const CharType *data() const;
- operator const CharType *() const;
- CharType operator[](size_t n) const;
+ If @a src is a non-owned buffer, a copy of its data is made using
+ wxStrdup(). If @a src is an owned buffer, the assignment behaves
+ in the usual way (reference count on buffer data is incremented).
+ */
+ wxCharTypeBuffer& operator=(const wxScopedCharTypeBuffer<T>& src);
+
+ /**
+ Extends the buffer to have size @a len.
+
+ Can only be called on buffers that don't share data with another
+ buffer (i.e. reference count of the data is 1).
+ */
+ bool extend(size_t len);
};
/**
This is a specialization of wxCharTypeBuffer<T> for @c char type.
- @todo provide better docs for this class
-
@nolibrary
@category{data}
*/
{
public:
typedef wxCharTypeBuffer<char> wxCharTypeBufferBase;
+ typedef wxScopedCharTypeBuffer<char> wxScopedCharTypeBufferBase;
wxCharBuffer(const wxCharTypeBufferBase& buf);
+ wxCharBuffer(const wxScopedCharTypeBufferBase& buf);
wxCharBuffer(const CharType *str = NULL);
wxCharBuffer(size_t len);
wxCharBuffer(const wxCStrData& cstr);
/**
This is a specialization of wxCharTypeBuffer<T> for @c wchar_t type.
- This class is available only when <tt>wxUSE_WCHAR_T==1</tt>
@nolibrary
@category{data}
{
public:
typedef wxCharTypeBuffer<wchar_t> wxCharTypeBufferBase;
+ typedef wxScopedCharTypeBuffer<wchar_t> wxScopedCharTypeBufferBase;
wxWCharBuffer(const wxCharTypeBufferBase& buf);
+ wxWCharBuffer(const wxScopedCharTypeBufferBase& buf);
wxWCharBuffer(const CharType *str = NULL);
wxWCharBuffer(size_t len);
wxWCharBuffer(const wxCStrData& cstr);
wxSTD ostream& operator<<(wxSTD ostream& os, const wxCStrData& str)
{
#if wxUSE_UNICODE && !wxUSE_UNICODE_UTF8
- const wxCharBuffer buf(str.AsCharBuf());
+ const wxScopedCharBuffer buf(str.AsCharBuf());
if ( !buf )
os.clear(wxSTD ios_base::failbit);
else
return os << str.c_str();
}
-wxSTD ostream& operator<<(wxSTD ostream& os, const wxCharBuffer& str)
+wxSTD ostream& operator<<(wxSTD ostream& os, const wxScopedCharBuffer& str)
{
return os << str.data();
}
#ifndef __BORLANDC__
-wxSTD ostream& operator<<(wxSTD ostream& os, const wxWCharBuffer& str)
+wxSTD ostream& operator<<(wxSTD ostream& os, const wxScopedWCharBuffer& str)
{
return os << str.data();
}
return wos << str.AsWChar();
}
-wxSTD wostream& operator<<(wxSTD wostream& wos, const wxWCharBuffer& str)
+wxSTD wostream& operator<<(wxSTD wostream& wos, const wxScopedWCharBuffer& str)
{
return wos << str.data();
}
// adding more fields to wxString and require profiling results
// to be sure that we really gain enough from them to justify
// doing it.
- wxCharBuffer buf(str->mb_str());
+ wxScopedCharBuffer buf(str->mb_str());
// if it failed, return empty string and not NULL to avoid crashes in code
// written with either wxWidgets 2 wxString or std::string behaviour in
wxString *str = wxConstCast(m_str, wxString);
// convert the string:
- wxWCharBuffer buf(str->wc_str());
+ wxScopedWCharBuffer buf(str->wc_str());
// notice that here, unlike above in AsChar(), conversion can't fail as our
// internal UTF-8 is always well-formed -- or the string was corrupted and
{
// anything to do?
if ( !psz || nLength == 0 )
- return SubstrBufFromMB(L"", 0);
+ return SubstrBufFromMB(wxWCharBuffer(L""), 0);
if ( nLength == npos )
nLength = wxNO_LEN;
size_t wcLen;
- wxWCharBuffer wcBuf(conv.cMB2WC(psz, nLength, &wcLen));
+ wxScopedWCharBuffer wcBuf(conv.cMB2WC(psz, nLength, &wcLen));
if ( !wcLen )
- return SubstrBufFromMB(_T(""), 0);
+ return SubstrBufFromMB(wxWCharBuffer(L""), 0);
else
return SubstrBufFromMB(wcBuf, wcLen);
}
{
// anything to do?
if ( !psz || nLength == 0 )
- return SubstrBufFromMB("", 0);
+ return SubstrBufFromMB(wxCharBuffer(""), 0);
// if psz is already in UTF-8, we don't have to do the roundtrip to
// wchar_t* and back:
// first convert to wide string:
size_t wcLen;
- wxWCharBuffer wcBuf(conv.cMB2WC(psz, nLength, &wcLen));
+ wxScopedWCharBuffer wcBuf(conv.cMB2WC(psz, nLength, &wcLen));
if ( !wcLen )
- return SubstrBufFromMB("", 0);
+ return SubstrBufFromMB(wxCharBuffer(""), 0);
// and then to UTF-8:
SubstrBufFromMB buf(ConvertStr(wcBuf, wcLen, wxMBConvStrictUTF8()));
{
// anything to do?
if ( !pwz || nLength == 0 )
- return SubstrBufFromWC("", 0);
+ return SubstrBufFromWC(wxCharBuffer(""), 0);
if ( nLength == npos )
nLength = wxNO_LEN;
size_t mbLen;
- wxCharBuffer mbBuf(conv.cWC2MB(pwz, nLength, &mbLen));
+ wxScopedCharBuffer mbBuf(conv.cWC2MB(pwz, nLength, &mbLen));
if ( !mbLen )
- return SubstrBufFromWC("", 0);
+ return SubstrBufFromWC(wxCharBuffer(""), 0);
else
return SubstrBufFromWC(mbBuf, mbLen);
}
#if wxUSE_UNICODE_WCHAR
//Convert wxString in Unicode mode to a multi-byte string
-const wxCharBuffer wxString::mb_str(const wxMBConv& conv) const
+const wxScopedCharBuffer wxString::mb_str(const wxMBConv& conv) const
{
return conv.cWC2MB(wx_str(), length() + 1 /* size, not length */, NULL);
}
#elif wxUSE_UNICODE_UTF8
-const wxWCharBuffer wxString::wc_str() const
+const wxScopedWCharBuffer wxString::wc_str() const
{
return wxMBConvStrictUTF8().cMB2WC
(
);
}
-const wxCharBuffer wxString::mb_str(const wxMBConv& conv) const
+const wxScopedCharBuffer wxString::mb_str(const wxMBConv& conv) const
{
if ( conv.IsUTF8() )
- return wxCharBuffer::CreateNonOwned(m_impl.c_str());
+ return wxScopedCharBuffer::CreateNonOwned(m_impl.c_str());
// FIXME-UTF8: use wc_str() here once we have buffers with length
size_t wcLen;
- wxWCharBuffer wcBuf(wxMBConvStrictUTF8().cMB2WC
- (
- m_impl.c_str(),
- m_impl.length() + 1, // size
- &wcLen
- ));
+ wxScopedWCharBuffer wcBuf
+ (
+ wxMBConvStrictUTF8().cMB2WC
+ (
+ m_impl.c_str(),
+ m_impl.length() + 1, // size
+ &wcLen
+ )
+ );
if ( !wcLen )
return wxCharBuffer("");
//Converts this string to a wide character string if unicode
//mode is not enabled and wxUSE_WCHAR_T is enabled
-const wxWCharBuffer wxString::wc_str(const wxMBConv& conv) const
+const wxScopedWCharBuffer wxString::wc_str(const wxMBConv& conv) const
{
return conv.cMB2WC(wx_str(), length() + 1 /* size, not length */, NULL);
}
return wxString(wxUniChar((wchar_t)c));
}
-const wxCharBuffer wxString::ToAscii() const
+const wxScopedCharBuffer wxString::ToAscii() const
{
// this will allocate enough space for the terminating NUL too
wxCharBuffer buffer(length());
// FIXME-UTF8: implement using iterators, remove #if
#if wxUSE_UNICODE_UTF8
- wxWCharBuffer maskBuf = mask.wc_str();
- wxWCharBuffer txtBuf = wc_str();
+ const wxScopedWCharBuffer maskBuf = mask.wc_str();
+ const wxScopedWCharBuffer txtBuf = wc_str();
const wxChar *pszMask = maskBuf.data();
const wxChar *pszTxt = txtBuf.data();
#else
}
};
-const wxWCharBuffer wxScanfConvertFormatW(const wchar_t *format)
+const wxScopedWCharBuffer wxScanfConvertFormatW(const wchar_t *format)
{
return wxScanfFormatConverterWchar().Convert(format);
}
if (!str)
return assign( wxUString() );
- wxWCharBuffer buffer = wxConvLibc.cMB2WC( str );
+ wxScopedWCharBuffer buffer = wxConvLibc.cMB2WC( str );
return assign( buffer );
}
if (!str)
return assign( wxUString() );
- wxWCharBuffer buffer = conv.cMB2WC( str );
+ wxScopedWCharBuffer buffer = conv.cMB2WC( str );
return assign( buffer );
}
-wxCharBuffer wxUString::utf8_str() const
+wxScopedCharBuffer wxUString::utf8_str() const
{
size_type utf8_length = 0;
const wxChar32 *ptr = data();
return result;
}
-wxU16CharBuffer wxUString::utf16_str() const
+wxScopedU16CharBuffer wxUString::utf16_str() const
{
size_type utf16_length = 0;
const wxChar32 *ptr = data();
m_name = name;
}
-wxVariant::wxVariant(const wxCharBuffer& val, const wxString& name)
+wxVariant::wxVariant(const wxScopedCharBuffer& val, const wxString& name)
{
m_data = new wxVariantDataString(wxString(val));
m_name = name;
}
-wxVariant::wxVariant(const wxWCharBuffer& val, const wxString& name)
+wxVariant::wxVariant(const wxScopedWCharBuffer& val, const wxString& name)
{
m_data = new wxVariantDataString(wxString(val));
m_name = name;
CPPUNIT_TEST( ExplicitConversion );
CPPUNIT_TEST( IndexedAccess );
CPPUNIT_TEST( BeforeAndAfter );
+ CPPUNIT_TEST( ScopedBuffers );
CPPUNIT_TEST_SUITE_END();
void String();
void ExplicitConversion();
void IndexedAccess();
void BeforeAndAfter();
+ void ScopedBuffers();
DECLARE_NO_COPY_CLASS(StringTestCase)
};
CPPUNIT_ASSERT_EQUAL( L"\xe7a=l\xe0", s.AfterLast(';') );
}
+void StringTestCase::ScopedBuffers()
+{
+ // wxString relies on efficient buffers, verify they work as they should
+
+ const char *literal = "Hello World!";
+
+ // non-owned buffer points to the string passed to it
+ wxScopedCharBuffer sbuf = wxScopedCharBuffer::CreateNonOwned(literal);
+ CPPUNIT_ASSERT( sbuf.data() == literal );
+
+ // a copy of scoped non-owned buffer still points to the same string
+ wxScopedCharBuffer sbuf2(sbuf);
+ CPPUNIT_ASSERT( sbuf.data() == sbuf2.data() );
+
+ // but assigning it to wxCharBuffer makes a full copy
+ wxCharBuffer buf(sbuf);
+ CPPUNIT_ASSERT( buf.data() != literal );
+ CPPUNIT_ASSERT_EQUAL( literal, buf.data() );
+
+ wxCharBuffer buf2 = sbuf;
+ CPPUNIT_ASSERT( buf2.data() != literal );
+ CPPUNIT_ASSERT_EQUAL( literal, buf2.data() );
+}