X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/300b44a9336a9610fef256afb412e8fb6b51840f..57e2b887a0e798ab5ab2921cdeba550f322b000c:/include/wx/string.h diff --git a/include/wx/string.h b/include/wx/string.h index a715911343..ac8c35b8bf 100644 --- a/include/wx/string.h +++ b/include/wx/string.h @@ -380,17 +380,32 @@ protected: // see the comment near wxString::iterator for why we need this struct WXDLLIMPEXP_BASE wxStringIteratorNode { - inline wxStringIteratorNode(const wxString *str, - wxStringImpl::const_iterator *citer); - inline wxStringIteratorNode(const wxString *str, - wxStringImpl::iterator *iter); - inline ~wxStringIteratorNode(); + wxStringIteratorNode() + : m_str(NULL), m_citer(NULL), m_iter(NULL), m_prev(NULL), m_next(NULL) {} + wxStringIteratorNode(const wxString *str, + wxStringImpl::const_iterator *citer) + { DoSet(str, citer, NULL); } + wxStringIteratorNode(const wxString *str, wxStringImpl::iterator *iter) + { DoSet(str, NULL, iter); } + ~wxStringIteratorNode() + { clear(); } + + inline void set(const wxString *str, wxStringImpl::const_iterator *citer) + { clear(); DoSet(str, citer, NULL); } + inline void set(const wxString *str, wxStringImpl::iterator *iter) + { clear(); DoSet(str, NULL, iter); } const wxString *m_str; wxStringImpl::const_iterator *m_citer; wxStringImpl::iterator *m_iter; wxStringIteratorNode *m_prev, *m_next; +private: + inline void clear(); + inline void DoSet(const wxString *str, + wxStringImpl::const_iterator *citer, + wxStringImpl::iterator *iter); + // the node belongs to a particular iterator instance, it's not copied // when a copy of the iterator is made DECLARE_NO_COPY_CLASS(wxStringIteratorNode) @@ -665,10 +680,11 @@ public: WX_STR_ITERATOR_IMPL(iterator, wxChar*, wxUniCharRef); public: + iterator() {} iterator(const iterator& i) : m_cur(i.m_cur), m_node(i.str(), &m_cur) {} iterator& operator=(const iterator& i) - { m_cur = i.m_cur; return *this; } + { m_cur = i.m_cur; m_node.set(i.str(), &m_cur); return *this; } reference operator*() { return wxUniCharRef::CreateForString(m_node, m_cur); } @@ -700,15 +716,16 @@ public: WX_STR_ITERATOR_IMPL(const_iterator, const wxChar*, wxUniChar); public: + const_iterator() {} const_iterator(const const_iterator& i) : m_cur(i.m_cur), m_node(i.str(), &m_cur) {} const_iterator(const iterator& i) : m_cur(i.m_cur), m_node(i.str(), &m_cur) {} const_iterator& operator=(const const_iterator& i) - { m_cur = i.m_cur; return *this; } + { m_cur = i.m_cur; m_node.set(i.str(), &m_cur); return *this; } const_iterator& operator=(const iterator& i) - { m_cur = i.m_cur; return *this; } + { m_cur = i.m_cur; m_node.set(i.str(), &m_cur); return *this; } reference operator*() const { return wxStringOperations::DecodeChar(m_cur); } @@ -742,6 +759,7 @@ public: WX_STR_ITERATOR_IMPL(iterator, wxChar*, wxUniCharRef); public: + iterator() {} iterator(const iterator& i) : m_cur(i.m_cur) {} reference operator*() @@ -771,6 +789,7 @@ public: WX_STR_ITERATOR_IMPL(const_iterator, const wxChar*, wxUniChar); public: + const_iterator() {} const_iterator(const const_iterator& i) : m_cur(i.m_cur) {} const_iterator(const iterator& i) : m_cur(i.m_cur) {} @@ -812,6 +831,7 @@ public: typedef typename T::reference reference; typedef typename T::pointer *pointer; + reverse_iterator_impl() {} reverse_iterator_impl(iterator_type i) : m_cur(i) {} reverse_iterator_impl(const reverse_iterator_impl& ri) : m_cur(ri.m_cur) {} @@ -1003,7 +1023,12 @@ public: wxString(const std::string& str) { assign(str.c_str(), str.length()); } #endif +#endif // wxUSE_STD_STRING + // Unlike ctor from std::string, we provide conversion to std::string only + // if wxUSE_STL and not merely wxUSE_STD_STRING (which is on by default), + // because it conflicts with operator const char/wchar_t*: +#if wxUSE_STL #if wxUSE_UNICODE_WCHAR && wxUSE_STL_BASED_WXSTRING // wxStringImpl is std::string in the encoding we want operator const wxStdWideString&() const { return m_impl; } @@ -1176,8 +1201,13 @@ public: // implicit conversion to C string operator wxCStrData() const { return c_str(); } + + // these operators conflict with operators for conversion to std::string, + // so they must be disabled in STL build: +#if !wxUSE_STL operator const char*() const { return c_str(); } operator const wchar_t*() const { return c_str(); } +#endif // implicit conversion to untyped pointer for compatibility with previous // wxWidgets versions: this is the same as conversion to const char * so it @@ -1205,11 +1235,14 @@ public: // the behaviour of these functions with the strings containing anything // else than 7 bit ASCII characters is undefined, use at your own risk. #if wxUSE_UNICODE + static wxString FromAscii(const char *ascii, size_t len); // string static wxString FromAscii(const char *ascii); // string static wxString FromAscii(const char ascii); // char const wxCharBuffer ToAscii() const; #else // ANSI static wxString FromAscii(const char *ascii) { return wxString( ascii ); } + static wxString FromAscii(const char *ascii, size_t len) + { return wxString( ascii, len ); } static wxString FromAscii(const char ascii) { return wxString( ascii ); } const char *ToAscii() const { return c_str(); } #endif // Unicode/!Unicode @@ -2977,7 +3010,7 @@ inline wxCStrData::wxCStrData(const wxCStrData& data) inline wxCStrData::~wxCStrData() { if ( m_owned ) - delete m_str; + delete wx_const_cast(wxString*, m_str); // cast to silence warnings } // simple cases for AsChar() and AsWChar(), the complicated ones are @@ -3089,40 +3122,40 @@ inline wxWCharBuffer::wxWCharBuffer(const wxCStrData& cstr) // implementation of wxStringIteratorNode inline methods // ---------------------------------------------------------------------------- -wxStringIteratorNode::wxStringIteratorNode(const wxString *str, - wxStringImpl::const_iterator *citer) - : m_str(str), - m_citer(citer), - m_iter(NULL), - m_prev(NULL), - m_next(str->m_iterators.ptr) +void wxStringIteratorNode::DoSet(const wxString *str, + wxStringImpl::const_iterator *citer, + wxStringImpl::iterator *iter) { - wx_const_cast(wxString*, m_str)->m_iterators.ptr = this; - if ( m_next ) - m_next->m_prev = this; -} - -wxStringIteratorNode::wxStringIteratorNode(const wxString *str, - wxStringImpl::iterator *iter) - : m_str(str), - m_citer(NULL), - m_iter(iter), - m_prev(NULL), - m_next(str->m_iterators.ptr) -{ - wx_const_cast(wxString*, m_str)->m_iterators.ptr = this; - if ( m_next) - m_next->m_prev = this; + m_prev = NULL; + m_iter = iter; + m_citer = citer; + m_str = str; + if ( str ) + { + m_next = str->m_iterators.ptr; + wx_const_cast(wxString*, m_str)->m_iterators.ptr = this; + if ( m_next ) + m_next->m_prev = this; + } + else + { + m_next = NULL; + } } -wxStringIteratorNode::~wxStringIteratorNode() +void wxStringIteratorNode::clear() { if ( m_next ) m_next->m_prev = m_prev; if ( m_prev ) m_prev->m_next = m_next; - else // first in the list + else if ( m_str ) // first in the list wx_const_cast(wxString*, m_str)->m_iterators.ptr = m_next; + + m_next = m_prev = NULL; + m_citer = NULL; + m_iter = NULL; + m_str = NULL; } #endif // wxUSE_UNICODE_UTF8