X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9aee0061fe0efe24cc3ece104a9370599086ea04..dc3065a56f1febf3de3b3bbf0904cf8fdc7f7c50:/include/wx/string.h diff --git a/include/wx/string.h b/include/wx/string.h index 72900dcfb1..3cb68a0df4 100644 --- a/include/wx/string.h +++ b/include/wx/string.h @@ -571,8 +571,6 @@ public: wxString(const wxString& str, size_t nLength) : m_impl(str.Mid(0, nLength).m_impl) {} - ~wxString(); - public: // standard types typedef wxUniChar value_type; @@ -640,7 +638,7 @@ public: iterator_name& operator-=(size_t n) \ { m_cur = wxString::AddToIter(m_cur, -(int)n); return *this; } \ \ - unsigned operator-(const iterator_name& i) const \ + difference_type operator-(const iterator_name& i) const \ { return wxString::DiffIters(m_cur, i.m_cur); } \ \ bool operator==(const iterator_name& i) const \ @@ -666,14 +664,14 @@ public: friend class WXDLLIMPEXP_BASE wxCStrData; \ \ private: \ - underlying_iterator m_cur; + underlying_iterator m_cur class const_iterator; class iterator { WX_STR_ITERATOR_IMPL(iterator, wxChar*, wxUniCharRef, - wxUniCharRef::CreateForString(m_cur)) + wxUniCharRef::CreateForString(m_cur)); friend class const_iterator; }; @@ -683,7 +681,7 @@ public: // NB: reference_type is intentionally value, not reference, the character // may be encoded differently in wxString data: WX_STR_ITERATOR_IMPL(const_iterator, const wxChar*, wxUniChar, - wxUniChar(*m_cur)) + wxUniChar(*m_cur)); public: const_iterator(const iterator& i) : m_cur(i.m_cur) {} @@ -2001,6 +1999,35 @@ private: private: wxStringImpl m_impl; + + // buffers for compatibility conversion from (char*)c_str() and + // (wchar_t*)c_str(): + // FIXME-UTF8: bechmark various approaches to keeping compatibility buffers + template + struct ConvertedBuffer + { + ConvertedBuffer() : m_buf(NULL) {} + ~ConvertedBuffer() + { free(m_buf); } + + operator const T*() const { return m_buf; } + + ConvertedBuffer& operator=(T *str) + { + free(m_buf); + m_buf = str; + return *this; + } + + T *m_buf; + }; +#if wxUSE_UNICODE + ConvertedBuffer m_convertedToChar; +#endif +#if !wxUSE_UNICODE_WCHAR + ConvertedBuffer m_convertedToWChar; +#endif + friend class WXDLLIMPEXP_BASE wxCStrData; }; #ifdef wxNEEDS_WXSTRING_PRINTF_MIXIN @@ -2308,7 +2335,7 @@ inline wxCStrData::~wxCStrData() inline wxCStrData::operator bool() const { return !m_str->empty(); -}; +} // simple cases for AsChar() and AsWChar(), the complicated ones are // in string.cpp @@ -2347,6 +2374,22 @@ inline wxUniChar wxCStrData::operator[](size_t n) const return m_str->at(m_offset + n); } +// ---------------------------------------------------------------------------- +// more wxCStrData operators +// ---------------------------------------------------------------------------- + +// we need to define those to allow "size_t pos = p - s.c_str()" where p is +// some pointer into the string +inline size_t operator-(const char *p, const wxCStrData& cs) +{ + return p - cs.AsChar(); +} + +inline size_t operator-(const wchar_t *p, const wxCStrData& cs) +{ + return p - cs.AsWChar(); +} + // ---------------------------------------------------------------------------- // implementation of wx[W]CharBuffer inline methods using wxCStrData // ----------------------------------------------------------------------------