summaryrefslogtreecommitdiff
path: root/sw/source/core/txtnode
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2012-07-31 15:52:38 +0200
committerMichael Stahl <mstahl@redhat.com>2012-07-31 20:26:45 +0200
commit43377e09d86dfcf800270a4c469ea5bd373392c6 (patch)
tree59f87eaabb523a9d168aaa3ef5e1bfb61c21c6fe /sw/source/core/txtnode
parent4623c603bde7678004fe6019f9d9e4b816a3d6c6 (diff)
fix some problems in previous STL conversion:
- use o3tl::find_partialorder_ptrequals to allow multiple hints on same position - GetPos must not dereference its argument - unused IsEquals Change-Id: I274203be96ff90d1e9a46bab17fd00355514a4fa
Diffstat (limited to 'sw/source/core/txtnode')
-rw-r--r--sw/source/core/txtnode/ndhints.cxx41
1 files changed, 21 insertions, 20 deletions
diff --git a/sw/source/core/txtnode/ndhints.cxx b/sw/source/core/txtnode/ndhints.cxx
index f3b8c9da3c4e..88ea48fb5536 100644
--- a/sw/source/core/txtnode/ndhints.cxx
+++ b/sw/source/core/txtnode/ndhints.cxx
@@ -39,15 +39,6 @@
inline void DumpHints(const SwpHtStart &, const SwpHtEnd &) { }
/*************************************************************************
- * inline IsEqual()
- *************************************************************************/
-
-static bool IsEqual( const SwTxtAttr &rHt1, const SwTxtAttr &rHt2 )
-{
- return &rHt1 == &rHt2;
-}
-
-/*************************************************************************
* IsLessStart()
*************************************************************************/
@@ -140,13 +131,15 @@ void SwpHintsArray::Insert( const SwTxtAttr *pHt )
{
Resort();
#if OSL_DEBUG_LEVEL > 0
- OSL_ENSURE(m_HintStarts.find( (SwTxtAttr*)pHt ) == m_HintStarts.end(),
+ OSL_ENSURE(
+ m_HintStarts.find(const_cast<SwTxtAttr*>(pHt)) == m_HintStarts.end(),
"Insert: hint already in HtStart");
- OSL_ENSURE(m_HintEnds.find( (SwTxtAttr*)pHt ) == m_HintEnds.end(),
+ OSL_ENSURE(
+ m_HintEnds.find(const_cast<SwTxtAttr*>(pHt)) == m_HintEnds.end(),
"Insert: hint already in HtEnd");
#endif
- m_HintStarts.insert( (SwTxtAttr*)pHt );
- m_HintEnds.insert( (SwTxtAttr*)pHt );
+ m_HintStarts.insert( const_cast<SwTxtAttr*>(pHt) );
+ m_HintEnds .insert( const_cast<SwTxtAttr*>(pHt) );
}
void SwpHintsArray::DeleteAtPos( const sal_uInt16 nPos )
@@ -157,15 +150,23 @@ void SwpHintsArray::DeleteAtPos( const sal_uInt16 nPos )
Resort();
- m_HintEnds.erase( pHt );
+ bool const done = m_HintEnds.erase(pHt);
+ assert(done);
}
sal_uInt16 SwpHintsArray::GetPos( const SwTxtAttr *pHt ) const
{
- SwpHtStart::const_iterator it = m_HintStarts.find( (SwTxtAttr*)pHt );
- if( it == m_HintStarts.end() )
- return USHRT_MAX;
- return it - m_HintStarts.begin();
+ // DO NOT use find() here!
+ // if called from SwTxtNode::InsertItem, pHt has already been deleted,
+ // so it cannot be dereferenced
+ for (size_t i = 0; i < m_HintStarts.size(); ++i)
+ {
+ if (m_HintStarts[i] == pHt)
+ {
+ return i;
+ }
+ }
+ return USHRT_MAX;
}
#ifdef DBG_UTIL
@@ -234,13 +235,13 @@ bool SwpHintsArray::Check() const
// --- Ueberkreuzungen ---
// 5) gleiche Pointer in beiden Arrays
- if( m_HintStarts.find( (SwTxtAttr*)pHt ) == m_HintStarts.end() )
+ if (m_HintStarts.find(const_cast<SwTxtAttr*>(pHt)) == m_HintStarts.end())
nIdx = STRING_LEN;
CHECK_ERR( STRING_LEN != nIdx, "HintsCheck: no GetStartOf" );
// 6) gleiche Pointer in beiden Arrays
- if( m_HintEnds.find( (SwTxtAttr*)pHt ) == m_HintEnds.end() )
+ if (m_HintEnds.find(const_cast<SwTxtAttr*>(pHt)) == m_HintEnds.end())
nIdx = STRING_LEN;
CHECK_ERR( STRING_LEN != nIdx, "HintsCheck: no GetEndOf" );