added wxCStrData::As[W]CharBuf() that doesn't keep converted string in memory for longer than needed
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45495 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -45,10 +45,10 @@ public:
|
|||||||
m_str[len] = (CharType)0;
|
m_str[len] = (CharType)0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static wxCharTypeBuffer CreateNonOwned(const CharType *str)
|
static const wxCharTypeBuffer CreateNonOwned(const CharType *str)
|
||||||
{
|
{
|
||||||
wxCharTypeBuffer buf;
|
wxCharTypeBuffer buf;
|
||||||
buf.m_str = str;
|
buf.m_str = wx_const_cast(CharType*, str);
|
||||||
buf.m_owned = false;
|
buf.m_owned = false;
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
@@ -157,6 +157,9 @@ class WXDLLIMPEXP_BASE wxCharBuffer : public wxCharTypeBuffer<char>
|
|||||||
public:
|
public:
|
||||||
typedef wxCharTypeBuffer<char> wxCharTypeBufferBase;
|
typedef wxCharTypeBuffer<char> wxCharTypeBufferBase;
|
||||||
|
|
||||||
|
wxCharBuffer(const wxCharTypeBufferBase& buf)
|
||||||
|
: wxCharTypeBufferBase(buf) {}
|
||||||
|
|
||||||
wxCharBuffer(const CharType *str = NULL) : wxCharTypeBufferBase(str) {}
|
wxCharBuffer(const CharType *str = NULL) : wxCharTypeBufferBase(str) {}
|
||||||
wxCharBuffer(size_t len) : wxCharTypeBufferBase(len) {}
|
wxCharBuffer(size_t len) : wxCharTypeBufferBase(len) {}
|
||||||
|
|
||||||
@@ -169,6 +172,9 @@ class WXDLLIMPEXP_BASE wxWCharBuffer : public wxCharTypeBuffer<wchar_t>
|
|||||||
public:
|
public:
|
||||||
typedef wxCharTypeBuffer<wchar_t> wxCharTypeBufferBase;
|
typedef wxCharTypeBuffer<wchar_t> wxCharTypeBufferBase;
|
||||||
|
|
||||||
|
wxWCharBuffer(const wxCharTypeBufferBase& buf)
|
||||||
|
: wxCharTypeBufferBase(buf) {}
|
||||||
|
|
||||||
wxWCharBuffer(const CharType *str = NULL) : wxCharTypeBufferBase(str) {}
|
wxWCharBuffer(const CharType *str = NULL) : wxCharTypeBufferBase(str) {}
|
||||||
wxWCharBuffer(size_t len) : wxCharTypeBufferBase(len) {}
|
wxWCharBuffer(size_t len) : wxCharTypeBufferBase(len) {}
|
||||||
|
|
||||||
|
@@ -212,6 +212,9 @@ public:
|
|||||||
|
|
||||||
operator const void*() const { return AsChar(); }
|
operator const void*() const { return AsChar(); }
|
||||||
|
|
||||||
|
inline const wxCharBuffer AsCharBuf() const;
|
||||||
|
inline const wxWCharBuffer AsWCharBuf() const;
|
||||||
|
|
||||||
inline wxString AsString() const;
|
inline wxString AsString() const;
|
||||||
|
|
||||||
// allow expressions like "c_str()[0]":
|
// allow expressions like "c_str()[0]":
|
||||||
@@ -2574,6 +2577,24 @@ inline const char* wxCStrData::AsChar() const
|
|||||||
}
|
}
|
||||||
#endif // !wxUSE_UNICODE
|
#endif // !wxUSE_UNICODE
|
||||||
|
|
||||||
|
inline const wxCharBuffer wxCStrData::AsCharBuf() const
|
||||||
|
{
|
||||||
|
#if !wxUSE_UNICODE
|
||||||
|
return wxCharBuffer::CreateNonOwned(AsChar());
|
||||||
|
#else
|
||||||
|
return AsString().mb_str();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const wxWCharBuffer wxCStrData::AsWCharBuf() const
|
||||||
|
{
|
||||||
|
#if wxUSE_UNICODE_WCHAR
|
||||||
|
return wxWCharBuffer::CreateNonOwned(AsWChar());
|
||||||
|
#else
|
||||||
|
return AsString().wc_str();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
inline wxString wxCStrData::AsString() const
|
inline wxString wxCStrData::AsString() const
|
||||||
{
|
{
|
||||||
if ( m_offset == 0 )
|
if ( m_offset == 0 )
|
||||||
@@ -2617,12 +2638,12 @@ inline size_t operator-(const wchar_t *p, const wxCStrData& cs)
|
|||||||
|
|
||||||
// FIXME-UTF8: move this to buffer.h
|
// FIXME-UTF8: move this to buffer.h
|
||||||
inline wxCharBuffer::wxCharBuffer(const wxCStrData& cstr)
|
inline wxCharBuffer::wxCharBuffer(const wxCStrData& cstr)
|
||||||
: wxCharTypeBufferBase(cstr.AsChar())
|
: wxCharTypeBufferBase(cstr.AsCharBuf())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
inline wxWCharBuffer::wxWCharBuffer(const wxCStrData& cstr)
|
inline wxWCharBuffer::wxWCharBuffer(const wxCStrData& cstr)
|
||||||
: wxCharTypeBufferBase(cstr.AsWChar())
|
: wxCharTypeBufferBase(cstr.AsWCharBuf())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -80,9 +80,9 @@ wxSTD ostream& operator<<(wxSTD ostream& os, const wxCStrData& str)
|
|||||||
{
|
{
|
||||||
// FIXME-UTF8: always, not only if wxUSE_UNICODE
|
// FIXME-UTF8: always, not only if wxUSE_UNICODE
|
||||||
#if wxUSE_UNICODE && !defined(__BORLANDC__)
|
#if wxUSE_UNICODE && !defined(__BORLANDC__)
|
||||||
return os << str.AsWChar();
|
return os << (const wchar_t*)str.AsWCharBuf();
|
||||||
#else
|
#else
|
||||||
return os << str.AsChar();
|
return os << (const char*)str.AsCharBuf();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user