fixed writing to wxUniCharRef after its 'parent' iterator was destroyed
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55285 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -673,7 +673,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
reference operator*()
|
reference operator*()
|
||||||
{ return wxUniCharRef::CreateForString(m_node, m_cur); }
|
{ return wxUniCharRef::CreateForString(*str(), m_cur); }
|
||||||
|
|
||||||
iterator operator+(ptrdiff_t n) const
|
iterator operator+(ptrdiff_t n) const
|
||||||
{ return iterator(str(), wxStringOperations::AddToIter(m_cur, n)); }
|
{ return iterator(str(), wxStringOperations::AddToIter(m_cur, n)); }
|
||||||
|
@@ -183,7 +183,7 @@ private:
|
|||||||
|
|
||||||
// create the reference
|
// create the reference
|
||||||
#if wxUSE_UNICODE_UTF8
|
#if wxUSE_UNICODE_UTF8
|
||||||
wxUniCharRef(wxStringIteratorNode& node, iterator pos) : m_node(node), m_pos(pos) {}
|
wxUniCharRef(wxString& str, iterator pos) : m_str(str), m_pos(pos) {}
|
||||||
#else
|
#else
|
||||||
wxUniCharRef(iterator pos) : m_pos(pos) {}
|
wxUniCharRef(iterator pos) : m_pos(pos) {}
|
||||||
#endif
|
#endif
|
||||||
@@ -195,8 +195,8 @@ public:
|
|||||||
// that must be used explicitly (this is more than using 'explicit'
|
// that must be used explicitly (this is more than using 'explicit'
|
||||||
// keyword on ctor!):
|
// keyword on ctor!):
|
||||||
#if wxUSE_UNICODE_UTF8
|
#if wxUSE_UNICODE_UTF8
|
||||||
static wxUniCharRef CreateForString(wxStringIteratorNode& node, iterator pos)
|
static wxUniCharRef CreateForString(wxString& str, iterator pos)
|
||||||
{ return wxUniCharRef(node, pos); }
|
{ return wxUniCharRef(str, pos); }
|
||||||
#else
|
#else
|
||||||
static wxUniCharRef CreateForString(iterator pos)
|
static wxUniCharRef CreateForString(iterator pos)
|
||||||
{ return wxUniCharRef(pos); }
|
{ return wxUniCharRef(pos); }
|
||||||
@@ -287,7 +287,7 @@ private:
|
|||||||
private:
|
private:
|
||||||
// reference to the string and pointer to the character in string
|
// reference to the string and pointer to the character in string
|
||||||
#if wxUSE_UNICODE_UTF8
|
#if wxUSE_UNICODE_UTF8
|
||||||
wxStringIteratorNode& m_node;
|
wxString& m_str;
|
||||||
#endif
|
#endif
|
||||||
iterator m_pos;
|
iterator m_pos;
|
||||||
};
|
};
|
||||||
|
@@ -106,8 +106,7 @@ wxUniCharRef& wxUniCharRef::operator=(const wxUniChar& c)
|
|||||||
// code -- in that case, we have to use wxStringImpl::replace() and
|
// code -- in that case, we have to use wxStringImpl::replace() and
|
||||||
// this invalidates all iterators, so we have to update them too:
|
// this invalidates all iterators, so we have to update them too:
|
||||||
|
|
||||||
wxString& str = *wx_const_cast(wxString*, m_node.m_str);
|
wxStringImpl& strimpl = m_str.m_impl;
|
||||||
wxStringImpl& strimpl = str.m_impl;
|
|
||||||
|
|
||||||
int iterDiff = lenNew - lenOld;
|
int iterDiff = lenNew - lenOld;
|
||||||
size_t posIdx = m_pos - strimpl.begin();
|
size_t posIdx = m_pos - strimpl.begin();
|
||||||
@@ -121,7 +120,7 @@ wxUniCharRef& wxUniCharRef::operator=(const wxUniChar& c)
|
|||||||
size_t *indexes = indexes_a;
|
size_t *indexes = indexes_a;
|
||||||
size_t iterNum = 0;
|
size_t iterNum = 0;
|
||||||
wxStringIteratorNode *it;
|
wxStringIteratorNode *it;
|
||||||
for ( it = str.m_iterators.ptr; it; it = it->m_next, ++iterNum )
|
for ( it = m_str.m_iterators.ptr; it; it = it->m_next, ++iterNum )
|
||||||
{
|
{
|
||||||
wxASSERT( it->m_iter || it->m_citer );
|
wxASSERT( it->m_iter || it->m_citer );
|
||||||
|
|
||||||
@@ -152,7 +151,7 @@ wxUniCharRef& wxUniCharRef::operator=(const wxUniChar& c)
|
|||||||
// finally, set the iterators to valid values again (note that this
|
// finally, set the iterators to valid values again (note that this
|
||||||
// updates m_pos as well):
|
// updates m_pos as well):
|
||||||
size_t i;
|
size_t i;
|
||||||
for ( i = 0, it = str.m_iterators.ptr; it; it = it->m_next, ++i )
|
for ( i = 0, it = m_str.m_iterators.ptr; it; it = it->m_next, ++i )
|
||||||
{
|
{
|
||||||
wxASSERT( i < iterNum );
|
wxASSERT( i < iterNum );
|
||||||
wxASSERT( it->m_iter || it->m_citer );
|
wxASSERT( it->m_iter || it->m_citer );
|
||||||
|
@@ -59,6 +59,7 @@ private:
|
|||||||
CPPUNIT_TEST( CStrDataOperators );
|
CPPUNIT_TEST( CStrDataOperators );
|
||||||
CPPUNIT_TEST( CStrDataImplicitConversion );
|
CPPUNIT_TEST( CStrDataImplicitConversion );
|
||||||
CPPUNIT_TEST( ExplicitConversion );
|
CPPUNIT_TEST( ExplicitConversion );
|
||||||
|
CPPUNIT_TEST( IndexedAccess );
|
||||||
CPPUNIT_TEST_SUITE_END();
|
CPPUNIT_TEST_SUITE_END();
|
||||||
|
|
||||||
void String();
|
void String();
|
||||||
@@ -89,6 +90,7 @@ private:
|
|||||||
void CStrDataOperators();
|
void CStrDataOperators();
|
||||||
void CStrDataImplicitConversion();
|
void CStrDataImplicitConversion();
|
||||||
void ExplicitConversion();
|
void ExplicitConversion();
|
||||||
|
void IndexedAccess();
|
||||||
|
|
||||||
DECLARE_NO_COPY_CLASS(StringTestCase)
|
DECLARE_NO_COPY_CLASS(StringTestCase)
|
||||||
};
|
};
|
||||||
@@ -826,3 +828,16 @@ void StringTestCase::ExplicitConversion()
|
|||||||
CPPUNIT_ASSERT( CheckStrConstWChar(s, s.wc_str()) );
|
CPPUNIT_ASSERT( CheckStrConstWChar(s, s.wc_str()) );
|
||||||
CPPUNIT_ASSERT( CheckStrWChar(s, s.wchar_str()) );
|
CPPUNIT_ASSERT( CheckStrWChar(s, s.wchar_str()) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void StringTestCase::IndexedAccess()
|
||||||
|
{
|
||||||
|
wxString s("bar");
|
||||||
|
CPPUNIT_ASSERT_EQUAL( 'r', s[2] );
|
||||||
|
|
||||||
|
// this tests for a possible bug in UTF-8 based wxString implementation:
|
||||||
|
// the 3rd character of the underlying byte string is going to change, but
|
||||||
|
// the 3rd character of wxString should remain the same
|
||||||
|
s[0] = L'\u00e9';
|
||||||
|
CPPUNIT_ASSERT_EQUAL( 'r', s[2] );
|
||||||
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user