X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f93d01be83e490fb20cce50a76821a3aac2cffba..9f50f9f1a161184359b7ee002d4f6bb7ecd8f04c:/include/wx/buffer.h diff --git a/include/wx/buffer.h b/include/wx/buffer.h index f5fc0f9208..afc0776994 100644 --- a/include/wx/buffer.h +++ b/include/wx/buffer.h @@ -14,8 +14,8 @@ #ifndef _WX_BUFFER_H #define _WX_BUFFER_H +#include "wx/wxchar.h" #include // strdup -#include // wchar_t // ---------------------------------------------------------------------------- // Special classes for (wide) character strings: they use malloc/free instead @@ -43,22 +43,24 @@ public: { m_str = src.m_str; // no reference count yet... - (wxCharBuffer)src.m_str = (char *)NULL; + ((wxCharBuffer*)&src)->m_str = (char *)NULL; } wxCharBuffer& operator=(const wxCharBuffer& src) { m_str = src.m_str; // no reference count yet... - (wxCharBuffer)src.m_str = (char *)NULL; + ((wxCharBuffer*)&src)->m_str = (char *)NULL; return *this; } operator const char *() const { return m_str; } + char operator[](size_t n) const { return m_str[n]; } private: char *m_str; }; +#if wxUSE_WCHAR_T class wxWCharBuffer { public: @@ -66,9 +68,12 @@ public: { wxASSERT_MSG( wcs, _T("NULL string in wxWCharBuffer") ); - m_wcs = wcs ? (wchar_t *)malloc((wcslen(wcs)+1)*sizeof(wchar_t)) - : (wchar_t *)NULL; - if (m_wcs) wcscpy(m_wcs, wcs); + if (wcs) { + size_t siz = (wcslen(wcs)+1)*sizeof(wchar_t); + m_wcs = (wchar_t *)malloc(siz); + memcpy(m_wcs, wcs, siz); + } + else m_wcs = (wchar_t *)NULL; } wxWCharBuffer(size_t len) { @@ -83,21 +88,23 @@ public: { m_wcs = src.m_wcs; // no reference count yet... - (wxWCharBuffer)src.m_wcs = (wchar_t *)NULL; + ((wxWCharBuffer*)&src)->m_wcs = (wchar_t *)NULL; } wxWCharBuffer& operator=(const wxWCharBuffer& src) { m_wcs = src.m_wcs; // no reference count yet... - (wxWCharBuffer)src.m_wcs = (wchar_t *)NULL; + ((wxWCharBuffer*)&src)->m_wcs = (wchar_t *)NULL; return *this; } operator const wchar_t *() const { return m_wcs; } - + wchar_t operator[](size_t n) const { return m_wcs[n]; } + private: wchar_t *m_wcs; }; +#endif #if wxUSE_UNICODE #define wxMB2WXbuf wxWCharBuffer