diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-09-19 16:35:10 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-09-25 12:48:47 +0200 |
commit | c6b8587eef3ead53418312c43012f4322789a33a (patch) | |
tree | 2b697f5eef431b00430318615fde3e4c4f877de8 /editeng | |
parent | 88e26267844ac96f39d341ef05bd1536f210af74 (diff) |
loplugin:useuniqueptr in SvxRTFParser
Change-Id: Ib759d5bcc7ce7cd9ea8ad752e5363375fa24e8f0
Reviewed-on: https://gerrit.libreoffice.org/60957
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'editeng')
-rw-r--r-- | editeng/source/rtf/rtfitem.cxx | 24 | ||||
-rw-r--r-- | editeng/source/rtf/svxrtf.cxx | 49 |
2 files changed, 31 insertions, 42 deletions
diff --git a/editeng/source/rtf/rtfitem.cxx b/editeng/source/rtf/rtfitem.cxx index ef0586291479..9579b8e9eaa2 100644 --- a/editeng/source/rtf/rtfitem.cxx +++ b/editeng/source/rtf/rtfitem.cxx @@ -214,7 +214,7 @@ void SvxRTFParser::ReadAttr( int nToken, SfxItemSet* pSet ) if( !bChkStkPos ) break; - SvxRTFItemStackType* pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back(); + SvxRTFItemStackType* pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back().get(); if( !pCurrent || (pCurrent->pSttNd->GetIdx() == pInsPos->GetNodeIdx() && pCurrent->nSttCnt == pInsPos->GetCntIdx() )) break; @@ -227,17 +227,17 @@ void SvxRTFParser::ReadAttr( int nToken, SfxItemSet* pSet ) pCurrent->nStyleNo ) { // Open a new Group - SvxRTFItemStackType* pNew = new SvxRTFItemStackType( - *pCurrent, *pInsPos, true ); + std::unique_ptr<SvxRTFItemStackType> pNew(new SvxRTFItemStackType( + *pCurrent, *pInsPos, true )); pNew->SetRTFDefaults( GetRTFDefaults() ); // "Set" all valid attributes up until this point AttrGroupEnd(); - pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back(); // can be changed after AttrGroupEnd! + pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back().get(); // can be changed after AttrGroupEnd! pNew->aAttrSet.SetParent( pCurrent ? &pCurrent->aAttrSet : nullptr ); - aAttrStack.push_back( pNew ); - pCurrent = pNew; + aAttrStack.push_back( std::move(pNew) ); + pCurrent = aAttrStack.back().get(); } else // continue to use this entry as a new one @@ -268,7 +268,7 @@ void SvxRTFParser::ReadAttr( int nToken, SfxItemSet* pSet ) { sal_uInt16 nStyleNo = -1 == nTokenValue ? 0 : sal_uInt16(nTokenValue); // set StyleNo to the current style on the AttrStack - SvxRTFItemStackType* pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back(); + SvxRTFItemStackType* pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back().get(); if( !pCurrent ) break; @@ -1686,7 +1686,7 @@ void SvxRTFParser::RTFPardPlain( bool const bPard, SfxItemSet** ppSet ) { if( !bNewGroup && !aAttrStack.empty() ) // not at the beginning of a new group { - SvxRTFItemStackType* pCurrent = aAttrStack.back(); + SvxRTFItemStackType* pCurrent = aAttrStack.back().get(); int nLastToken = GetStackPtr(-1)->nTokenId; bool bNewStkEntry = true; @@ -1697,15 +1697,15 @@ void SvxRTFParser::RTFPardPlain( bool const bPard, SfxItemSet** ppSet ) if (pCurrent->aAttrSet.Count() || pCurrent->m_pChildList || pCurrent->nStyleNo) { // open a new group - SvxRTFItemStackType* pNew = new SvxRTFItemStackType( *pCurrent, *pInsPos, true ); + std::unique_ptr<SvxRTFItemStackType> pNew(new SvxRTFItemStackType( *pCurrent, *pInsPos, true )); pNew->SetRTFDefaults( GetRTFDefaults() ); // Set all until here valid attributes AttrGroupEnd(); - pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back(); // can be changed after AttrGroupEnd! + pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back().get(); // can be changed after AttrGroupEnd! pNew->aAttrSet.SetParent( pCurrent ? &pCurrent->aAttrSet : nullptr ); - aAttrStack.push_back( pNew ); - pCurrent = pNew; + aAttrStack.push_back( std::move(pNew) ); + pCurrent = aAttrStack.back().get(); } else { diff --git a/editeng/source/rtf/svxrtf.cxx b/editeng/source/rtf/svxrtf.cxx index 5864354802cd..bfd67ed4ced4 100644 --- a/editeng/source/rtf/svxrtf.cxx +++ b/editeng/source/rtf/svxrtf.cxx @@ -585,12 +585,7 @@ void SvxRTFParser::ClearColorTbl() void SvxRTFParser::ClearAttrStack() { - for( size_t nCnt = aAttrStack.size(); nCnt; --nCnt ) - { - SvxRTFItemStackType* pTmp = aAttrStack.back(); - aAttrStack.pop_back(); - delete pTmp; - } + aAttrStack.clear(); } OUString& SvxRTFParser::DelCharAtEnd( OUString& rStr, const sal_Unicode cDel ) @@ -621,18 +616,18 @@ const vcl::Font& SvxRTFParser::GetFont( sal_uInt16 nId ) SvxRTFItemStackType* SvxRTFParser::GetAttrSet_() { - SvxRTFItemStackType* pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back(); - SvxRTFItemStackType* pNew; + SvxRTFItemStackType* pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back().get(); + std::unique_ptr<SvxRTFItemStackType> pNew; if( pCurrent ) - pNew = new SvxRTFItemStackType( *pCurrent, *pInsPos, false/*bCopyAttr*/ ); + pNew.reset(new SvxRTFItemStackType( *pCurrent, *pInsPos, false/*bCopyAttr*/ )); else - pNew = new SvxRTFItemStackType( *pAttrPool, &aWhichMap[0], - *pInsPos ); + pNew.reset(new SvxRTFItemStackType( *pAttrPool, &aWhichMap[0], + *pInsPos )); pNew->SetRTFDefaults( GetRTFDefaults() ); - aAttrStack.push_back( pNew ); + aAttrStack.push_back( std::move(pNew) ); bNewGroup = false; - return pNew; + return aAttrStack.back().get(); } @@ -684,9 +679,8 @@ void SvxRTFParser::AttrGroupEnd() // process the current, delete from Stack { if( !aAttrStack.empty() ) { - SvxRTFItemStackType *pOld = aAttrStack.empty() ? nullptr : aAttrStack.back(); - aAttrStack.pop_back(); - SvxRTFItemStackType *pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back(); + std::unique_ptr<SvxRTFItemStackType> pOld = std::move(aAttrStack.back()); + SvxRTFItemStackType *pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back().get(); do { // middle check loop sal_Int32 nOldSttNdIdx = pOld->pSttNd->GetIdx(); @@ -778,7 +772,7 @@ void SvxRTFParser::AttrGroupEnd() // process the current, delete from Stack if( pCurrent ) { - pCurrent->Add(std::unique_ptr<SvxRTFItemStackType>(pOld)); + pCurrent->Add(std::move(pOld)); pCurrent->Add(std::move(pNew)); } else @@ -786,10 +780,9 @@ void SvxRTFParser::AttrGroupEnd() // process the current, delete from Stack // Last off the stack, thus cache it until the next text was // read. (Span no attributes!) - m_AttrSetList.push_back(std::unique_ptr<SvxRTFItemStackType>(pOld)); + m_AttrSetList.push_back(std::move(pOld)); m_AttrSetList.push_back(std::move(pNew)); } - pOld = nullptr; // Do not delete pOld break; } } @@ -813,7 +806,7 @@ void SvxRTFParser::AttrGroupEnd() // process the current, delete from Stack if( pCurrent ) { - pCurrent->Add(std::unique_ptr<SvxRTFItemStackType>(pOld)); + pCurrent->Add(std::move(pOld)); // split up and create new entry, because it make no sense // to create a "so long" depend list. Bug 95010 if (bCrsrBack && 50 < pCurrent->m_pChildList->size()) @@ -823,23 +816,21 @@ void SvxRTFParser::AttrGroupEnd() // process the current, delete from Stack bCrsrBack = false; // Open a new Group. - SvxRTFItemStackType* pNew = new SvxRTFItemStackType( - *pCurrent, *pInsPos, true ); + std::unique_ptr<SvxRTFItemStackType> pNew(new SvxRTFItemStackType( + *pCurrent, *pInsPos, true )); pNew->SetRTFDefaults( GetRTFDefaults() ); // Set all until here valid Attributes AttrGroupEnd(); - pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back(); // can be changed after AttrGroupEnd! + pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back().get(); // can be changed after AttrGroupEnd! pNew->aAttrSet.SetParent( pCurrent ? &pCurrent->aAttrSet : nullptr ); - aAttrStack.push_back( pNew ); + aAttrStack.push_back( std::move(pNew) ); } } else // Last off the stack, thus cache it until the next text was // read. (Span no attributes!) - m_AttrSetList.push_back(std::unique_ptr<SvxRTFItemStackType>(pOld)); - - pOld = nullptr; + m_AttrSetList.push_back(std::move(pOld)); } if( bCrsrBack ) @@ -848,8 +839,6 @@ void SvxRTFParser::AttrGroupEnd() // process the current, delete from Stack } while( false ); - delete pOld; - bNewGroup = false; } } @@ -889,7 +878,7 @@ void SvxRTFParser::SetAttrSet( SvxRTFItemStackType &rSet ) // Has no text been inserted yet? (SttPos from the top Stack entry!) bool SvxRTFParser::IsAttrSttPos() { - SvxRTFItemStackType* pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back(); + SvxRTFItemStackType* pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back().get(); return !pCurrent || (pCurrent->pSttNd->GetIdx() == pInsPos->GetNodeIdx() && pCurrent->nSttCnt == pInsPos->GetCntIdx()); } |