sw/source/filter/html/htmlcss1.cxx | 10 - sw/source/filter/html/htmlform.cxx | 8 - sw/source/filter/html/htmlsect.cxx | 18 +-- sw/source/filter/html/htmltab.cxx | 189 ++++++++++++++++--------------------- sw/source/filter/html/swhtml.cxx | 44 +++----- sw/source/filter/html/swhtml.hxx | 23 ++-- 6 files changed, 131 insertions(+), 161 deletions(-)
New commits: commit e79b7a51cc4f425112377e2c3cee7f27961557ef Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Thu Sep 27 09:11:36 2018 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Mon Oct 1 08:16:13 2018 +0200 loplugin:useuniqueptr in SwPendingStack and simplify, no need for a linked list here, a vector will do fine Change-Id: I0aa3d518ceec305aaa0607306bdf816a52507c58 Reviewed-on: https://gerrit.libreoffice.org/61109 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/source/filter/html/htmlcss1.cxx b/sw/source/filter/html/htmlcss1.cxx index 8518decf45e8..9cdc2880e0c1 100644 --- a/sw/source/filter/html/htmlcss1.cxx +++ b/sw/source/filter/html/htmlcss1.cxx @@ -1725,15 +1725,13 @@ bool SwHTMLParser::FileDownload( const OUString& rURL, void SwHTMLParser::InsertLink() { bool bFinishDownload = false; - if( m_pPendStack ) + if( !m_vPendingStack.empty() ) { OSL_ENSURE( ShouldFinishFileDownload(), "Pending-Stack without File-Download?" ); - SwPendingStack* pTmp = m_pPendStack->pNext; - delete m_pPendStack; - m_pPendStack = pTmp; - OSL_ENSURE( !m_pPendStack, "Where does the Pending-Stack come from?" ); + m_vPendingStack.pop_back(); + assert( m_vPendingStack.empty() && "Where does the Pending-Stack come from?" ); bFinishDownload = true; } @@ -1778,7 +1776,7 @@ void SwHTMLParser::InsertLink() // The style was load asynchronously and is only available // on the next continue call. Therefore we must create a // Pending stack, so that we will return to here. - m_pPendStack = new SwPendingStack( HtmlTokenId::LINK, m_pPendStack ); + m_vPendingStack.emplace_back( HtmlTokenId::LINK ); } } else diff --git a/sw/source/filter/html/htmlform.cxx b/sw/source/filter/html/htmlform.cxx index 358cac7388af..fc03ba994a9d 100644 --- a/sw/source/filter/html/htmlform.cxx +++ b/sw/source/filter/html/htmlform.cxx @@ -1379,7 +1379,7 @@ void SwHTMLParser::EndForm( bool bAppend ) void SwHTMLParser::InsertInput() { - assert(m_pPendStack == nullptr); + assert(m_vPendingStack.empty()); if( !m_pFormImpl || !m_pFormImpl->GetFormComps().is() ) return; @@ -1851,7 +1851,7 @@ void SwHTMLParser::InsertInput() void SwHTMLParser::NewTextArea() { - assert(m_pPendStack == nullptr); + assert(m_vPendingStack.empty()); OSL_ENSURE( !m_bTextArea, "TextArea in TextArea?" ); OSL_ENSURE( !m_pFormImpl || !m_pFormImpl->GetFCompPropSet().is(), @@ -2133,7 +2133,7 @@ void SwHTMLParser::InsertTextAreaText( HtmlTokenId nToken ) void SwHTMLParser::NewSelect() { - assert(m_pPendStack == nullptr); + assert(m_vPendingStack.empty()); OSL_ENSURE( !m_bSelect, "Select in Select?" ); OSL_ENSURE( !m_pFormImpl || !m_pFormImpl->GetFCompPropSet().is(), @@ -2347,7 +2347,7 @@ void SwHTMLParser::NewSelect() void SwHTMLParser::EndSelect() { - assert(m_pPendStack == nullptr); + assert(m_vPendingStack.empty()); OSL_ENSURE( m_bSelect, "no Select" ); OSL_ENSURE( m_pFormImpl && m_pFormImpl->GetFCompPropSet().is(), diff --git a/sw/source/filter/html/htmltab.cxx b/sw/source/filter/html/htmltab.cxx index 6dd841891b19..050066c8f0bc 100644 --- a/sw/source/filter/html/htmltab.cxx +++ b/sw/source/filter/html/htmltab.cxx @@ -2744,7 +2744,7 @@ SvxBrushItem* SwHTMLParser::CreateBrushItem( const Color *pColor, return pBrushItem; } -class SectionSaveStruct : public SwPendingStackData +class SectionSaveStruct : public SwPendingData { sal_uInt16 m_nBaseFontStMinSave, m_nFontStMinSave, m_nFontStHeadStartSave; sal_uInt16 m_nDefListDeepSave; @@ -3188,7 +3188,7 @@ void SwHTMLParser::RegisterDrawObjectToTable( HTMLTable *pCurTable, void SwHTMLParser::BuildTableCell( HTMLTable *pCurTable, bool bReadOptions, bool bHead ) { - if( !IsParserWorking() && !m_pPendStack ) + if( !IsParserWorking() && m_vPendingStack.empty() ) return; ::comphelper::FlagRestorationGuard g(m_isInTableStructure, false); @@ -3196,15 +3196,13 @@ void SwHTMLParser::BuildTableCell( HTMLTable *pCurTable, bool bReadOptions, HtmlTokenId nToken = HtmlTokenId::NONE; bool bPending = false; - if( m_pPendStack ) + if( !m_vPendingStack.empty() ) { - xSaveStruct.reset(static_cast<CellSaveStruct*>(m_pPendStack->pData)); + xSaveStruct.reset(static_cast<CellSaveStruct*>(m_vPendingStack.back().pData.release())); - SwPendingStack* pTmp = m_pPendStack->pNext; - delete m_pPendStack; - m_pPendStack = pTmp; - nToken = m_pPendStack ? m_pPendStack->nToken : GetSaveToken(); - bPending = SvParserState::Error == eState && m_pPendStack != nullptr; + m_vPendingStack.pop_back(); + nToken = !m_vPendingStack.empty() ? m_vPendingStack.back().nToken : GetSaveToken(); + bPending = SvParserState::Error == eState && !m_vPendingStack.empty(); SaveState( nToken ); } @@ -3587,9 +3585,9 @@ void SwHTMLParser::BuildTableCell( HTMLTable *pCurTable, bool bReadOptions, nToken = FilterToken( nToken ); - OSL_ENSURE( m_pPendStack || !m_bCallNextToken || xSaveStruct->IsInSection(), + OSL_ENSURE( !m_vPendingStack.empty() || !m_bCallNextToken || xSaveStruct->IsInSection(), "Where is the section??" ); - if( !m_pPendStack && m_bCallNextToken && xSaveStruct->IsInSection() ) + if( m_vPendingStack.empty() && m_bCallNextToken && xSaveStruct->IsInSection() ) { // Call NextToken directly (e.g. ignore the content of floating frames or applets) NextToken( nToken ); @@ -3617,7 +3615,7 @@ void SwHTMLParser::BuildTableCell( HTMLTable *pCurTable, bool bReadOptions, { bool bHasToFly = false; SvxAdjust eTabAdjust = SvxAdjust::End; - if( !m_pPendStack ) + if( m_vPendingStack.empty() ) { // only if we create a new table, but not if we're still // reading in the table after a Pending @@ -3771,7 +3769,7 @@ void SwHTMLParser::BuildTableCell( HTMLTable *pCurTable, bool bReadOptions, break; } - OSL_ENSURE( !bPending || !m_pPendStack, + OSL_ENSURE( !bPending || m_vPendingStack.empty(), "SwHTMLParser::BuildTableCell: There is a PendStack again" ); bPending = false; if( IsParserWorking() ) @@ -3783,9 +3781,9 @@ void SwHTMLParser::BuildTableCell( HTMLTable *pCurTable, bool bReadOptions, if( SvParserState::Pending == GetStatus() ) { - m_pPendStack = new SwPendingStack( bHead ? HtmlTokenId::TABLEHEADER_ON - : HtmlTokenId::TABLEDATA_ON, m_pPendStack ); - m_pPendStack->pData = xSaveStruct.release(); + m_vPendingStack.emplace_back( bHead ? HtmlTokenId::TABLEHEADER_ON + : HtmlTokenId::TABLEDATA_ON ); + m_vPendingStack.back().pData = std::move(xSaveStruct); return; } @@ -3879,7 +3877,7 @@ void SwHTMLParser::BuildTableCell( HTMLTable *pCurTable, bool bReadOptions, xSaveStruct.reset(); } -class RowSaveStruct : public SwPendingStackData +class RowSaveStruct : public SwPendingData { public: SvxAdjust eAdjust; @@ -3897,22 +3895,20 @@ void SwHTMLParser::BuildTableRow( HTMLTable *pCurTable, bool bReadOptions, { // <TR> was already read - if( !IsParserWorking() && !m_pPendStack ) + if( !IsParserWorking() && m_vPendingStack.empty() ) return; HtmlTokenId nToken = HtmlTokenId::NONE; std::unique_ptr<RowSaveStruct> xSaveStruct; bool bPending = false; - if( m_pPendStack ) + if( !m_vPendingStack.empty() ) { - xSaveStruct.reset(static_cast<RowSaveStruct*>(m_pPendStack->pData)); + xSaveStruct.reset(static_cast<RowSaveStruct*>(m_vPendingStack.back().pData.release())); - SwPendingStack* pTmp = m_pPendStack->pNext; - delete m_pPendStack; - m_pPendStack = pTmp; - nToken = m_pPendStack ? m_pPendStack->nToken : GetSaveToken(); - bPending = SvParserState::Error == eState && m_pPendStack != nullptr; + m_vPendingStack.pop_back(); + nToken = !m_vPendingStack.empty() ? m_vPendingStack.back().nToken : GetSaveToken(); + bPending = SvParserState::Error == eState && !m_vPendingStack.empty(); SaveState( nToken ); } @@ -3986,10 +3982,10 @@ void SwHTMLParser::BuildTableRow( HTMLTable *pCurTable, bool bReadOptions, nToken = FilterToken( nToken ); - OSL_ENSURE( m_pPendStack || !m_bCallNextToken || + OSL_ENSURE( !m_vPendingStack.empty() || !m_bCallNextToken || pCurTable->GetContext() || pCurTable->HasParentSection(), "Where is the section??" ); - if( !m_pPendStack && m_bCallNextToken && + if( m_vPendingStack.empty() && m_bCallNextToken && (pCurTable->GetContext() || pCurTable->HasParentSection()) ) { /// Call NextToken directly (e.g. ignore the content of floating frames or applets) @@ -4069,7 +4065,7 @@ void SwHTMLParser::BuildTableRow( HTMLTable *pCurTable, bool bReadOptions, break; } - OSL_ENSURE( !bPending || !m_pPendStack, + OSL_ENSURE( !bPending || m_vPendingStack.empty(), "SwHTMLParser::BuildTableRow: There is a PendStack again" ); bPending = false; if( IsParserWorking() ) @@ -4081,8 +4077,8 @@ void SwHTMLParser::BuildTableRow( HTMLTable *pCurTable, bool bReadOptions, if( SvParserState::Pending == GetStatus() ) { - m_pPendStack = new SwPendingStack( HtmlTokenId::TABLEROW_ON, m_pPendStack ); - m_pPendStack->pData = xSaveStruct.release(); + m_vPendingStack.emplace_back( HtmlTokenId::TABLEROW_ON ); + m_vPendingStack.back().pData = std::move(xSaveStruct); } else { @@ -4098,22 +4094,20 @@ void SwHTMLParser::BuildTableSection( HTMLTable *pCurTable, bool bHead ) { // <THEAD>, <TBODY> resp. <TFOOT> were read already - if( !IsParserWorking() && !m_pPendStack ) + if( !IsParserWorking() && m_vPendingStack.empty() ) return; HtmlTokenId nToken = HtmlTokenId::NONE; bool bPending = false; std::unique_ptr<RowSaveStruct> xSaveStruct; - if( m_pPendStack ) + if( !m_vPendingStack.empty() ) { - xSaveStruct.reset(static_cast<RowSaveStruct*>(m_pPendStack->pData)); + xSaveStruct.reset(static_cast<RowSaveStruct*>(m_vPendingStack.back().pData.release())); - SwPendingStack* pTmp = m_pPendStack->pNext; - delete m_pPendStack; - m_pPendStack = pTmp; - nToken = m_pPendStack ? m_pPendStack->nToken : GetSaveToken(); - bPending = SvParserState::Error == eState && m_pPendStack != nullptr; + m_vPendingStack.pop_back(); + nToken = !m_vPendingStack.empty() ? m_vPendingStack.back().nToken : GetSaveToken(); + bPending = SvParserState::Error == eState && !m_vPendingStack.empty(); SaveState( nToken ); } @@ -4160,10 +4154,10 @@ void SwHTMLParser::BuildTableSection( HTMLTable *pCurTable, nToken = FilterToken( nToken ); - OSL_ENSURE( m_pPendStack || !m_bCallNextToken || + OSL_ENSURE( !m_vPendingStack.empty() || !m_bCallNextToken || pCurTable->GetContext() || pCurTable->HasParentSection(), "Where is the section?" ); - if( !m_pPendStack && m_bCallNextToken && + if( m_vPendingStack.empty() && m_bCallNextToken && (pCurTable->GetContext() || pCurTable->HasParentSection()) ) { // Call NextToken directly (e.g. ignore the content of floating frames or applets) @@ -4229,7 +4223,7 @@ void SwHTMLParser::BuildTableSection( HTMLTable *pCurTable, NextToken( nToken ); } - OSL_ENSURE( !bPending || !m_pPendStack, + OSL_ENSURE( !bPending || m_vPendingStack.empty(), "SwHTMLParser::BuildTableSection: There is a PendStack again" ); bPending = false; if( IsParserWorking() ) @@ -4241,9 +4235,9 @@ void SwHTMLParser::BuildTableSection( HTMLTable *pCurTable, if( SvParserState::Pending == GetStatus() ) { - m_pPendStack = new SwPendingStack( bHead ? HtmlTokenId::THEAD_ON - : HtmlTokenId::TBODY_ON, m_pPendStack ); - m_pPendStack->pData = xSaveStruct.release(); + m_vPendingStack.emplace_back( bHead ? HtmlTokenId::THEAD_ON + : HtmlTokenId::TBODY_ON ); + m_vPendingStack.back().pData = std::move(xSaveStruct); } else { @@ -4254,7 +4248,7 @@ void SwHTMLParser::BuildTableSection( HTMLTable *pCurTable, // now we stand (perhaps) in front of <TBODY>,... or </TABLE> } -struct TableColGrpSaveStruct : public SwPendingStackData +struct TableColGrpSaveStruct : public SwPendingData { sal_uInt16 nColGrpSpan; sal_uInt16 nColGrpWidth; @@ -4284,29 +4278,28 @@ void SwHTMLParser::BuildTableColGroup( HTMLTable *pCurTable, { // <COLGROUP> was read already if bReadOptions is set - if( !IsParserWorking() && !m_pPendStack ) + if( !IsParserWorking() && m_vPendingStack.empty() ) return; HtmlTokenId nToken = HtmlTokenId::NONE; bool bPending = false; - TableColGrpSaveStruct* pSaveStruct; + std::unique_ptr<TableColGrpSaveStruct> pSaveStruct; - if( m_pPendStack ) + if( !m_vPendingStack.empty() ) { - pSaveStruct = static_cast<TableColGrpSaveStruct*>(m_pPendStack->pData); + pSaveStruct.reset(static_cast<TableColGrpSaveStruct*>(m_vPendingStack.back().pData.release())); - SwPendingStack* pTmp = m_pPendStack->pNext; - delete m_pPendStack; - m_pPendStack = pTmp; - nToken = m_pPendStack ? m_pPendStack->nToken : GetSaveToken(); - bPending = SvParserState::Error == eState && m_pPendStack != nullptr; + + m_vPendingStack.pop_back(); + nToken = !m_vPendingStack.empty() ? m_vPendingStack.back().nToken : GetSaveToken(); + bPending = SvParserState::Error == eState && !m_vPendingStack.empty(); SaveState( nToken ); } else { - pSaveStruct = new TableColGrpSaveStruct; + pSaveStruct.reset(new TableColGrpSaveStruct); if( bReadOptions ) { const HTMLOptions& rColGrpOptions = GetOptions(); @@ -4358,10 +4351,10 @@ void SwHTMLParser::BuildTableColGroup( HTMLTable *pCurTable, nToken = FilterToken( nToken ); - OSL_ENSURE( m_pPendStack || !m_bCallNextToken || + OSL_ENSURE( !m_vPendingStack.empty() || !m_bCallNextToken || pCurTable->GetContext() || pCurTable->HasParentSection(), "Where is the section?" ); - if( !m_pPendStack && m_bCallNextToken && + if( m_vPendingStack.empty() && m_bCallNextToken && (pCurTable->GetContext() || pCurTable->HasParentSection()) ) { // Call NextToken directly (e.g. ignore the content of floating frames or applets) @@ -4451,7 +4444,7 @@ void SwHTMLParser::BuildTableColGroup( HTMLTable *pCurTable, NextToken( nToken ); } - OSL_ENSURE( !bPending || !m_pPendStack, + OSL_ENSURE( !bPending || m_vPendingStack.empty(), "SwHTMLParser::BuildTableColGrp: There is a PendStack again" ); bPending = false; if( IsParserWorking() ) @@ -4463,13 +4456,12 @@ void SwHTMLParser::BuildTableColGroup( HTMLTable *pCurTable, if( SvParserState::Pending == GetStatus() ) { - m_pPendStack = new SwPendingStack( HtmlTokenId::COL_ON, m_pPendStack ); - m_pPendStack->pData = pSaveStruct; + m_vPendingStack.emplace_back( HtmlTokenId::COL_ON ); + m_vPendingStack.back().pData = std::move(pSaveStruct); } else { pSaveStruct->CloseColGroup( pCurTable ); - delete pSaveStruct; } } @@ -4512,21 +4504,19 @@ void SwHTMLParser::BuildTableCaption( HTMLTable *pCurTable ) { // <CAPTION> was read already - if( !IsParserWorking() && !m_pPendStack ) + if( !IsParserWorking() && m_vPendingStack.empty() ) return; HtmlTokenId nToken = HtmlTokenId::NONE; std::unique_ptr<CaptionSaveStruct> xSaveStruct; - if( m_pPendStack ) + if( !m_vPendingStack.empty() ) { - xSaveStruct.reset(static_cast<CaptionSaveStruct*>(m_pPendStack->pData)); + xSaveStruct.reset(static_cast<CaptionSaveStruct*>(m_vPendingStack.back().pData.release())); - SwPendingStack* pTmp = m_pPendStack->pNext; - delete m_pPendStack; - m_pPendStack = pTmp; - nToken = m_pPendStack ? m_pPendStack->nToken : GetSaveToken(); - OSL_ENSURE( !m_pPendStack, "Where does a PendStack coming from?" ); + m_vPendingStack.pop_back(); + nToken = !m_vPendingStack.empty() ? m_vPendingStack.back().nToken : GetSaveToken(); + OSL_ENSURE( m_vPendingStack.empty(), "Where does a PendStack coming from?" ); SaveState( nToken ); } @@ -4595,7 +4585,7 @@ void SwHTMLParser::BuildTableCaption( HTMLTable *pCurTable ) switch( nToken ) { case HtmlTokenId::TABLE_ON: - if( !m_pPendStack ) + if( m_vPendingStack.empty() ) { xSaveStruct->m_xTable = m_xTable; bool bHasToFly = xSaveStruct->m_xTable.get() != pCurTable; @@ -4625,13 +4615,10 @@ void SwHTMLParser::BuildTableCaption( HTMLTable *pCurTable ) bDone = true; break; default: - if( m_pPendStack ) + if( !m_vPendingStack.empty() ) { - SwPendingStack* pTmp = m_pPendStack->pNext; - delete m_pPendStack; - m_pPendStack = pTmp; - - OSL_ENSURE( !pTmp, "Further it can't go!" ); + m_vPendingStack.pop_back(); + OSL_ENSURE( m_vPendingStack.empty(), "Further it can't go!" ); } if( IsParserWorking() ) @@ -4648,8 +4635,8 @@ void SwHTMLParser::BuildTableCaption( HTMLTable *pCurTable ) if( SvParserState::Pending==GetStatus() ) { - m_pPendStack = new SwPendingStack( HtmlTokenId::CAPTION_ON, m_pPendStack ); - m_pPendStack->pData = xSaveStruct.release(); + m_vPendingStack.emplace_back( HtmlTokenId::CAPTION_ON ); + m_vPendingStack.back().pData = std::move(xSaveStruct); return; } @@ -4693,7 +4680,7 @@ void SwHTMLParser::BuildTableCaption( HTMLTable *pCurTable ) *m_pPam->GetPoint() = xSaveStruct->GetPos(); } -class TableSaveStruct : public SwPendingStackData +class TableSaveStruct : public SwPendingData { public: std::shared_ptr<HTMLTable> m_xCurrentTable; @@ -5006,7 +4993,7 @@ std::shared_ptr<HTMLTable> SwHTMLParser::BuildTable(SvxAdjust eParentAdjust, if (aGuard.TooDeep()) eState = SvParserState::Error; - if (!IsParserWorking() && !m_pPendStack) + if (!IsParserWorking() && m_vPendingStack.empty()) return std::shared_ptr<HTMLTable>(); ::comphelper::FlagRestorationGuard g(m_isInTableStructure, true); @@ -5014,15 +5001,13 @@ std::shared_ptr<HTMLTable> SwHTMLParser::BuildTable(SvxAdjust eParentAdjust, bool bPending = false; std::unique_ptr<TableSaveStruct> xSaveStruct; - if( m_pPendStack ) + if( !m_vPendingStack.empty() ) { - xSaveStruct.reset(static_cast<TableSaveStruct*>(m_pPendStack->pData)); + xSaveStruct.reset(static_cast<TableSaveStruct*>(m_vPendingStack.back().pData.release())); - SwPendingStack* pTmp = m_pPendStack->pNext; - delete m_pPendStack; - m_pPendStack = pTmp; - nToken = m_pPendStack ? m_pPendStack->nToken : GetSaveToken(); - bPending = SvParserState::Error == eState && m_pPendStack != nullptr; + m_vPendingStack.pop_back(); + nToken = !m_vPendingStack.empty() ? m_vPendingStack.back().nToken : GetSaveToken(); + bPending = SvParserState::Error == eState && !m_vPendingStack.empty(); SaveState( nToken ); } @@ -5060,10 +5045,10 @@ std::shared_ptr<HTMLTable> SwHTMLParser::BuildTable(SvxAdjust eParentAdjust, nToken = FilterToken( nToken ); - OSL_ENSURE( m_pPendStack || !m_bCallNextToken || + OSL_ENSURE( !m_vPendingStack.empty() || !m_bCallNextToken || xCurTable->GetContext() || xCurTable->HasParentSection(), "Where is the section?" ); - if( !m_pPendStack && m_bCallNextToken && + if( m_vPendingStack.empty() && m_bCallNextToken && (xCurTable->GetContext() || xCurTable->HasParentSection()) ) { /// Call NextToken directly (e.g. ignore the content of floating frames or applets) @@ -5129,7 +5114,7 @@ std::shared_ptr<HTMLTable> SwHTMLParser::BuildTable(SvxAdjust eParentAdjust, break; } - OSL_ENSURE( !bPending || !m_pPendStack, + OSL_ENSURE( !bPending || m_vPendingStack.empty(), "SwHTMLParser::BuildTable: There is a PendStack again" ); bPending = false; if( IsParserWorking() ) @@ -5141,8 +5126,8 @@ std::shared_ptr<HTMLTable> SwHTMLParser::BuildTable(SvxAdjust eParentAdjust, if( SvParserState::Pending == GetStatus() ) { - m_pPendStack = new SwPendingStack( HtmlTokenId::TABLE_ON, m_pPendStack ); - m_pPendStack->pData = xSaveStruct.release(); + m_vPendingStack.emplace_back( HtmlTokenId::TABLE_ON ); + m_vPendingStack.back().pData = std::move(xSaveStruct); return std::shared_ptr<HTMLTable>(); } diff --git a/sw/source/filter/html/swhtml.cxx b/sw/source/filter/html/swhtml.cxx index 5bd52b7b06f8..cbda0a8dcbf9 100644 --- a/sw/source/filter/html/swhtml.cxx +++ b/sw/source/filter/html/swhtml.cxx @@ -259,7 +259,6 @@ SwHTMLParser::SwHTMLParser( SwDoc* pD, SwPaM& rCursor, SvStream& rIn, m_sBaseURL( rBaseURL ), m_xAttrTab(new HTMLAttrTable), m_pNumRuleInfo( new SwHTMLNumRuleInfo ), - m_pPendStack( nullptr ), m_xDoc( pD ), m_pActionViewShell( nullptr ), m_pSttNdIdx( nullptr ), @@ -477,15 +476,9 @@ SwHTMLParser::~SwHTMLParser() OSL_ENSURE(!m_xTable.get(), "It exists still a open table"); m_pImageMaps.reset(); - OSL_ENSURE( !m_pPendStack, + OSL_ENSURE( m_vPendingStack.empty(), "SwHTMLParser::~SwHTMLParser: Here should not be Pending-Stack anymore" ); - while( m_pPendStack ) - { - SwPendingStack* pTmp = m_pPendStack; - m_pPendStack = m_pPendStack->pNext; - delete pTmp->pData; - delete pTmp; - } + m_vPendingStack.clear(); m_xDoc.clear(); @@ -634,16 +627,16 @@ void SwHTMLParser::Continue( HtmlTokenId nToken ) // of NextToken. if( SvParserState::Error == eState ) { - OSL_ENSURE( !m_pPendStack || m_pPendStack->nToken != HtmlTokenId::NONE, + OSL_ENSURE( m_vPendingStack.empty() || m_vPendingStack.back().nToken != HtmlTokenId::NONE, "SwHTMLParser::Continue: Pending-Stack without Token" ); - if( m_pPendStack && m_pPendStack->nToken != HtmlTokenId::NONE ) - NextToken( m_pPendStack->nToken ); - OSL_ENSURE( !m_pPendStack, + if( !m_vPendingStack.empty() && m_vPendingStack.back().nToken != HtmlTokenId::NONE ) + NextToken( m_vPendingStack.back().nToken ); + OSL_ENSURE( m_vPendingStack.empty(), "SwHTMLParser::Continue: There is again a Pending-Stack" ); } else { - HTMLParser::Continue( m_pPendStack ? m_pPendStack->nToken : nToken ); + HTMLParser::Continue( !m_vPendingStack.empty() ? m_vPendingStack.back().nToken : nToken ); } // disable progress bar again @@ -962,14 +955,14 @@ void SwHTMLParser::NextToken( HtmlTokenId nToken ) // Was the import cancelled by SFX? If a pending stack // exists, clean it. eState = SvParserState::Error; - OSL_ENSURE( !m_pPendStack || m_pPendStack->nToken != HtmlTokenId::NONE, + OSL_ENSURE( m_vPendingStack.empty() || m_vPendingStack.back().nToken != HtmlTokenId::NONE, "SwHTMLParser::NextToken: Pending-Stack without token" ); - if( 1 == m_xDoc->getReferenceCount() || !m_pPendStack ) + if( 1 == m_xDoc->getReferenceCount() || m_vPendingStack.empty() ) return ; } #if OSL_DEBUG_LEVEL > 0 - if( m_pPendStack ) + if( !m_vPendingStack.empty() ) { switch( nToken ) { @@ -985,7 +978,7 @@ void SwHTMLParser::NextToken( HtmlTokenId nToken ) case HtmlTokenId::SELECT_OFF: break; default: - OSL_ENSURE( !m_pPendStack, "Unknown token for Pending-Stack" ); + OSL_ENSURE( m_vPendingStack.empty(), "Unknown token for Pending-Stack" ); break; } } @@ -994,7 +987,7 @@ void SwHTMLParser::NextToken( HtmlTokenId nToken ) // The following special cases have to be treated before the // filter detection, because Netscape doesn't reference the content // of the title for filter detection either. - if( !m_pPendStack ) + if( m_vPendingStack.empty() ) { if( m_bInTitle ) { @@ -1065,7 +1058,7 @@ void SwHTMLParser::NextToken( HtmlTokenId nToken ) // The following special cases may or have to be treated after the // filter detection - if( !m_pPendStack ) + if( m_vPendingStack.empty() ) { if( m_bInFloatingFrame ) { @@ -1731,7 +1724,7 @@ void SwHTMLParser::NextToken( HtmlTokenId nToken ) break; case HtmlTokenId::TABLE_ON: - if( m_pPendStack ) + if( !m_vPendingStack.empty() ) BuildTable( SvxAdjust::End ); else { diff --git a/sw/source/filter/html/swhtml.hxx b/sw/source/filter/html/swhtml.hxx index bcd620b84562..667407d4a9b0 100644 --- a/sw/source/filter/html/swhtml.hxx +++ b/sw/source/filter/html/swhtml.hxx @@ -52,7 +52,7 @@ class SwHTMLForm_Impl; class SwApplet_Impl; struct SwHTMLFootEndNote_Impl; class HTMLTableCnts; -struct SwPendingStack; +struct SwPending; class SvxCSS1PropertyInfo; struct ImplSVEvent; @@ -372,7 +372,7 @@ class SwHTMLParser : public SfxHTMLParser, public SwClient std::unique_ptr<SwCSS1Parser> m_pCSS1Parser; // Style-Sheet-Parser std::unique_ptr<SwHTMLNumRuleInfo> m_pNumRuleInfo; - SwPendingStack *m_pPendStack; + std::vector<SwPending> m_vPendingStack; rtl::Reference<SwDoc> m_xDoc; SwPaM *m_pPam; // SwPosition should be enough, or ?? @@ -930,19 +930,18 @@ public: static OUString StripQueryFromPath(const OUString& rBase, const OUString& rPath); }; -struct SwPendingStackData +struct SwPendingData { - virtual ~SwPendingStackData() {} + virtual ~SwPendingData() {} }; -struct SwPendingStack +struct SwPending { HtmlTokenId nToken; - SwPendingStackData* pData; - SwPendingStack* pNext; + std::unique_ptr<SwPendingData> pData; - SwPendingStack( HtmlTokenId nTkn, SwPendingStack* pNxt ) - : nToken( nTkn ), pData( nullptr ), pNext( pNxt ) + SwPending( HtmlTokenId nTkn ) + : nToken( nTkn ) {} }; commit 7e4631c544146a9b5a4087aab992aedfed6e8c03 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Thu Sep 27 08:44:49 2018 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Mon Oct 1 08:16:02 2018 +0200 loplugin:useuniqueptr in SwHTMLParser Change-Id: Ib6d101ef6640d45d467cc749b9d1b1261a4ac452 Reviewed-on: https://gerrit.libreoffice.org/61108 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/source/filter/html/htmlsect.cxx b/sw/source/filter/html/htmlsect.cxx index 606b754d630e..b084a27d41c7 100644 --- a/sw/source/filter/html/htmlsect.cxx +++ b/sw/source/filter/html/htmlsect.cxx @@ -261,8 +261,8 @@ void SwHTMLParser::NewDivision( HtmlTokenId nToken ) bAppended = true; } } - HTMLAttrs *pPostIts = bAppended ? nullptr : new HTMLAttrs; - SetAttr( true, true, pPostIts ); + std::unique_ptr<std::deque<std::unique_ptr<HTMLAttr>>> pPostIts(bAppended ? nullptr : new std::deque<std::unique_ptr<HTMLAttr>>); + SetAttr( true, true, pPostIts.get() ); // make name of section unique const OUString aName( m_xDoc->GetUniqueSectionName( !aId.isEmpty() ? &aId : nullptr ) ); @@ -357,9 +357,8 @@ void SwHTMLParser::NewDivision( HtmlTokenId nToken ) if( pPostIts ) { // move still existing PostIts in the first paragraph of the table - InsertAttrs( *pPostIts ); - delete pPostIts; - pPostIts = nullptr; + InsertAttrs( std::move(*pPostIts) ); + pPostIts.reset(); } xCntxt->SetSpansSection( true ); @@ -684,8 +683,8 @@ void SwHTMLParser::NewMultiCol( sal_uInt16 columnsFromCss ) bAppended = true; } } - HTMLAttrs *pPostIts = bAppended ? nullptr : new HTMLAttrs; - SetAttr( true, true, pPostIts ); + std::unique_ptr<std::deque<std::unique_ptr<HTMLAttr>>> pPostIts(bAppended ? nullptr : new std::deque<std::unique_ptr<HTMLAttr>>); + SetAttr( true, true, pPostIts.get() ); // Make section name unique. OUString aName( m_xDoc->GetUniqueSectionName( !aId.isEmpty() ? &aId : nullptr ) ); @@ -744,9 +743,8 @@ void SwHTMLParser::NewMultiCol( sal_uInt16 columnsFromCss ) if( pPostIts ) { // Move pending PostIts into the section. - InsertAttrs( *pPostIts ); - delete pPostIts; - pPostIts = nullptr; + InsertAttrs( std::move(*pPostIts) ); + pPostIts.reset(); } xCntxt->SetSpansSection( true ); diff --git a/sw/source/filter/html/htmltab.cxx b/sw/source/filter/html/htmltab.cxx index cea48ce2645c..6dd841891b19 100644 --- a/sw/source/filter/html/htmltab.cxx +++ b/sw/source/filter/html/htmltab.cxx @@ -3372,7 +3372,7 @@ void SwHTMLParser::BuildTableCell( HTMLTable *pCurTable, bool bReadOptions, m_nContextStAttrMin ) ); // end all open attributes and open them again behind the table - HTMLAttrs *pPostIts = nullptr; + std::unique_ptr<std::deque<std::unique_ptr<HTMLAttr>>> pPostIts; if( !bForceFrame && (bTopTable || pCurTable->HasParentSection()) ) { SplitAttrTab(pTCntxt->xAttrTab, bTopTable); @@ -3384,16 +3384,16 @@ void SwHTMLParser::BuildTableCell( HTMLTable *pCurTable, bool bReadOptions, if( (bTopTable && !bAppended) || (!bTopTable && !bParentLFStripped && !m_pPam->GetPoint()->nContent.GetIndex()) ) - pPostIts = new HTMLAttrs; - SetAttr( bTopTable, bTopTable, pPostIts ); + pPostIts.reset(new std::deque<std::unique_ptr<HTMLAttr>>); + SetAttr( bTopTable, bTopTable, pPostIts.get() ); } else { SaveAttrTab(pTCntxt->xAttrTab); if( bTopTable && !bAppended ) { - pPostIts = new HTMLAttrs; - SetAttr( true, true, pPostIts ); + pPostIts.reset(new std::deque<std::unique_ptr<HTMLAttr>>); + SetAttr( true, true, pPostIts.get() ); } } m_bNoParSpace = false; @@ -3523,9 +3523,8 @@ void SwHTMLParser::BuildTableCell( HTMLTable *pCurTable, bool bReadOptions, if( !bAppended && pPostIts ) { // set still-existing PostIts to the first paragraph of the table - InsertAttrs( *pPostIts ); - delete pPostIts; - pPostIts = nullptr; + InsertAttrs( std::move(*pPostIts) ); + pPostIts.reset(); } pTCntxt->SetTableNode( const_cast<SwTableNode *>(pNd->FindTableNode()) ); @@ -3553,9 +3552,8 @@ void SwHTMLParser::BuildTableCell( HTMLTable *pCurTable, bool bReadOptions, if( pPostIts ) { // move still existing PostIts to the end of the current paragraph - InsertAttrs( *pPostIts ); - delete pPostIts; - pPostIts = nullptr; + InsertAttrs( std::move(*pPostIts) ); + pPostIts.reset(); } } diff --git a/sw/source/filter/html/swhtml.cxx b/sw/source/filter/html/swhtml.cxx index d3c513530216..5bd52b7b06f8 100644 --- a/sw/source/filter/html/swhtml.cxx +++ b/sw/source/filter/html/swhtml.cxx @@ -2683,7 +2683,7 @@ SwViewShell *SwHTMLParser::CheckActionViewShell() } void SwHTMLParser::SetAttr_( bool bChkEnd, bool bBeforeTable, - HTMLAttrs *pPostIts ) + std::deque<std::unique_ptr<HTMLAttr>> *pPostIts ) { std::unique_ptr<SwPaM> pAttrPam( new SwPaM( *m_pPam->GetPoint() ) ); const SwNodeIndex& rEndIdx = m_pPam->GetPoint()->nNode; @@ -2882,7 +2882,7 @@ void SwHTMLParser::SetAttr_( bool bChkEnd, bool bBeforeTable, if( pPostIts && (SwFieldIds::Postit == nFieldWhich || SwFieldIds::Script == nFieldWhich) ) { - pPostIts->push_front( pAttr ); + pPostIts->emplace_front( pAttr ); } else { @@ -3422,14 +3422,13 @@ void SwHTMLParser::InsertAttr( const SfxPoolItem& rItem, bool bInsAtStart ) m_aSetAttrTab.push_back( pTmp ); } -void SwHTMLParser::InsertAttrs( HTMLAttrs& rAttrs ) +void SwHTMLParser::InsertAttrs( std::deque<std::unique_ptr<HTMLAttr>> rAttrs ) { while( !rAttrs.empty() ) { - HTMLAttr *pAttr = rAttrs.front(); + std::unique_ptr<HTMLAttr> pAttr = std::move(rAttrs.front()); InsertAttr( pAttr->GetItem(), false ); rAttrs.pop_front(); - delete pAttr; } } diff --git a/sw/source/filter/html/swhtml.hxx b/sw/source/filter/html/swhtml.hxx index fffff878e01b..bcd620b84562 100644 --- a/sw/source/filter/html/swhtml.hxx +++ b/sw/source/filter/html/swhtml.hxx @@ -483,9 +483,9 @@ class SwHTMLParser : public SfxHTMLParser, public SwClient DECL_LINK( AsyncCallback, void*, void ); // set attribute on document - void SetAttr_( bool bChkEnd, bool bBeforeTable, HTMLAttrs *pPostIts ); + void SetAttr_( bool bChkEnd, bool bBeforeTable, std::deque<std::unique_ptr<HTMLAttr>> *pPostIts ); void SetAttr( bool bChkEnd = true, bool bBeforeTable = false, - HTMLAttrs *pPostIts = nullptr ) + std::deque<std::unique_ptr<HTMLAttr>> *pPostIts = nullptr ) { if( !m_aSetAttrTab.empty() || !m_aMoveFlyFrames.empty() ) SetAttr_( bChkEnd, bBeforeTable, pPostIts ); @@ -510,7 +510,7 @@ class SwHTMLParser : public SfxHTMLParser, public SwClient void SplitAttrTab(std::shared_ptr<HTMLAttrTable> const & rNewAttrTab, bool bMoveEndBack); void RestoreAttrTab(std::shared_ptr<HTMLAttrTable> const & rNewAttrTab); void InsertAttr( const SfxPoolItem& rItem, bool bInsAtStart ); - void InsertAttrs( HTMLAttrs& rAttrs ); + void InsertAttrs( std::deque<std::unique_ptr<HTMLAttr>> rAttrs ); bool DoPositioning( SfxItemSet &rItemSet, SvxCSS1PropertyInfo &rPropInfo, _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits