summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2019-01-11 13:28:39 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2019-01-14 07:02:20 +0100
commit0f257c1dce36b69741a96ec9c10158867c48f610 (patch)
treefedaaa2041c4a16566aa2c3bff3758a299c677da /sw
parent74db00dc36cec6390329e44636deda7f43e2891a (diff)
use unique_ptr in CSS1Parser
Change-Id: I4553233f7cf2f54a94154f41e899183490eec3e9 Reviewed-on: https://gerrit.libreoffice.org/66184 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sw')
-rw-r--r--sw/source/filter/html/parcss1.cxx54
-rw-r--r--sw/source/filter/html/parcss1.hxx12
-rw-r--r--sw/source/filter/html/svxcss1.cxx25
-rw-r--r--sw/source/filter/html/svxcss1.hxx11
4 files changed, 35 insertions, 67 deletions
diff --git a/sw/source/filter/html/parcss1.cxx b/sw/source/filter/html/parcss1.cxx
index ba64adad7be6..9a14ddc1be07 100644
--- a/sw/source/filter/html/parcss1.cxx
+++ b/sw/source/filter/html/parcss1.cxx
@@ -733,13 +733,12 @@ void CSS1Parser::ParseStyleSheet()
void CSS1Parser::ParseRule()
{
// selector
- CSS1Selector *pSelector = ParseSelector();
+ std::unique_ptr<CSS1Selector> pSelector = ParseSelector();
if( !pSelector )
return;
// process selector
- if( SelectorParsed( pSelector, true ) )
- delete pSelector;
+ SelectorParsed( std::move(pSelector), true );
LOOP_CHECK_DECL
@@ -757,8 +756,7 @@ void CSS1Parser::ParseRule()
return;
// process selector
- if( SelectorParsed( pSelector, false ) )
- delete pSelector;
+ SelectorParsed( std::move(pSelector), false );
}
// '{'
@@ -768,13 +766,12 @@ void CSS1Parser::ParseRule()
// declaration
OUString aProperty;
- CSS1Expression *pExpr = ParseDeclaration( aProperty );
+ std::unique_ptr<CSS1Expression> pExpr = ParseDeclaration( aProperty );
if( !pExpr )
return;
// process expression
- if( DeclarationParsed( aProperty, pExpr ) )
- delete pExpr;
+ DeclarationParsed( aProperty, std::move(pExpr) );
LOOP_CHECK_RESTART
@@ -789,12 +786,11 @@ void CSS1Parser::ParseRule()
// declaration
if( CSS1_IDENT == nToken )
{
- CSS1Expression *pExp = ParseDeclaration( aProperty );
+ std::unique_ptr<CSS1Expression> pExp = ParseDeclaration( aProperty );
if( pExp )
{
// process expression
- if( DeclarationParsed( aProperty, pExp ) )
- delete pExp;
+ DeclarationParsed( aProperty, std::move(pExp));
}
}
}
@@ -824,9 +820,10 @@ void CSS1Parser::ParseRule()
// pseude_element
// : IDENT
-CSS1Selector *CSS1Parser::ParseSelector()
+std::unique_ptr<CSS1Selector> CSS1Parser::ParseSelector()
{
- CSS1Selector *pRoot = nullptr, *pLast = nullptr;
+ std::unique_ptr<CSS1Selector> pRoot;
+ CSS1Selector *pLast = nullptr;
bool bDone = false;
CSS1Selector *pNew = nullptr;
@@ -932,7 +929,7 @@ CSS1Selector *CSS1Parser::ParseSelector()
if( pLast )
pLast->SetNext( pNew );
else
- pRoot = pNew;
+ pRoot.reset(pNew);
pLast = pNew;
pNew = nullptr;
@@ -991,9 +988,10 @@ CSS1Selector *CSS1Parser::ParseSelector()
// the sign is only used for numeric values (except PERCENTAGE)
// and it's applied on nValue!
-CSS1Expression *CSS1Parser::ParseDeclaration( OUString& rProperty )
+std::unique_ptr<CSS1Expression> CSS1Parser::ParseDeclaration( OUString& rProperty )
{
- CSS1Expression *pRoot = nullptr, *pLast = nullptr;
+ std::unique_ptr<CSS1Expression> pRoot;
+ CSS1Expression *pLast = nullptr;
// property
if( CSS1_IDENT != nToken )
@@ -1079,7 +1077,7 @@ CSS1Expression *CSS1Parser::ParseDeclaration( OUString& rProperty )
if( pLast )
pLast->SetNext( pNew );
else
- pRoot = pNew;
+ pRoot.reset(pNew);
pLast = pNew;
pNew = nullptr;
@@ -1166,15 +1164,12 @@ void CSS1Parser::ParseStyleOption( const OUString& rIn )
}
OUString aProperty;
- CSS1Expression *pExpr = ParseDeclaration( aProperty );
+ std::unique_ptr<CSS1Expression> pExpr = ParseDeclaration( aProperty );
if( !pExpr )
- {
return;
- }
// process expression
- if( DeclarationParsed( aProperty, pExpr ) )
- delete pExpr;
+ DeclarationParsed( aProperty, std::move(pExpr) );
LOOP_CHECK_DECL
@@ -1186,28 +1181,23 @@ void CSS1Parser::ParseStyleOption( const OUString& rIn )
nToken = GetNextToken();
if( CSS1_IDENT==nToken )
{
- CSS1Expression *pExp = ParseDeclaration( aProperty );
+ std::unique_ptr<CSS1Expression> pExp = ParseDeclaration( aProperty );
if( pExp )
{
// process expression
- if( DeclarationParsed( aProperty, pExp ) )
- delete pExp;
+ DeclarationParsed( aProperty, std::move(pExp) );
}
}
}
}
-bool CSS1Parser::SelectorParsed( CSS1Selector* /* pSelector */, bool /*bFirst*/ )
+void CSS1Parser::SelectorParsed( std::unique_ptr<CSS1Selector> /* pSelector */, bool /*bFirst*/ )
{
- // delete selector
- return true;
}
-bool CSS1Parser::DeclarationParsed( const OUString& /*rProperty*/,
- const CSS1Expression * /* pExpr */ )
+void CSS1Parser::DeclarationParsed( const OUString& /*rProperty*/,
+ std::unique_ptr<CSS1Expression> /* pExpr */ )
{
- // delete declaration
- return true;
}
CSS1Selector::~CSS1Selector()
diff --git a/sw/source/filter/html/parcss1.hxx b/sw/source/filter/html/parcss1.hxx
index 1e8c287fdced..29c3ce3d2a0f 100644
--- a/sw/source/filter/html/parcss1.hxx
+++ b/sw/source/filter/html/parcss1.hxx
@@ -207,8 +207,8 @@ class CSS1Parser
// parse parts of the grammar
void ParseRule();
- CSS1Selector *ParseSelector();
- CSS1Expression *ParseDeclaration( OUString& rProperty );
+ std::unique_ptr<CSS1Selector> ParseSelector();
+ std::unique_ptr<CSS1Expression> ParseDeclaration( OUString& rProperty );
protected:
void ParseStyleSheet();
@@ -236,18 +236,16 @@ protected:
*
* @param pSelector The selector that was parsed
* @param bFirst if true, a new declaration starts with this selector
- * @return If true, the selector will be deleted. (Returns always true?)
*/
- virtual bool SelectorParsed( CSS1Selector* pSelector, bool bFirst );
+ virtual void SelectorParsed( std::unique_ptr<CSS1Selector> pSelector, bool bFirst );
/** Called after a declaration or property was parsed
*
* @param rProperty The declaration/property
* @param pExpr ???
- * @return If true, the declaration will be deleted. (Returns always true?)
*/
- virtual bool DeclarationParsed( const OUString& rProperty,
- const CSS1Expression *pExpr );
+ virtual void DeclarationParsed( const OUString& rProperty,
+ std::unique_ptr<CSS1Expression> pExpr );
public:
CSS1Parser();
diff --git a/sw/source/filter/html/svxcss1.cxx b/sw/source/filter/html/svxcss1.cxx
index e2726b18be34..c052f3bccde7 100644
--- a/sw/source/filter/html/svxcss1.cxx
+++ b/sw/source/filter/html/svxcss1.cxx
@@ -665,7 +665,7 @@ void SvxCSS1Parser::StyleParsed( const CSS1Selector * /*pSelector*/,
// you see nothing is happening here
}
-bool SvxCSS1Parser::SelectorParsed( CSS1Selector *pSelector, bool bFirst )
+void SvxCSS1Parser::SelectorParsed( std::unique_ptr<CSS1Selector> pSelector, bool bFirst )
{
if( bFirst )
{
@@ -682,22 +682,7 @@ bool SvxCSS1Parser::SelectorParsed( CSS1Selector *pSelector, bool bFirst )
m_Selectors.clear();
}
- m_Selectors.push_back(std::unique_ptr<CSS1Selector>(pSelector));
-
- return false; // Selector saved. Deleting deadly!
-}
-
-bool SvxCSS1Parser::DeclarationParsed( const OUString& rProperty,
- const CSS1Expression *pExpr )
-{
- OSL_ENSURE( pExpr, "DeclarationParsed() without Expression" );
-
- if( !pExpr )
- return true;
-
- ParseProperty( rProperty, pExpr );
-
- return true; // the declaration isn't needed anymore. Delete it!
+ m_Selectors.push_back(std::move(pSelector));
}
SvxCSS1Parser::SvxCSS1Parser( SfxItemPool& rPool, const OUString& rBaseURL,
@@ -3150,8 +3135,8 @@ static bool CSS1PropEntryFindCompare(CSS1PropEntry const & lhs, OUString const &
return s.compareToIgnoreAsciiCaseAscii(lhs.pName) > 0;
}
-void SvxCSS1Parser::ParseProperty( const OUString& rProperty,
- const CSS1Expression *pExpr )
+void SvxCSS1Parser::DeclarationParsed( const OUString& rProperty,
+ std::unique_ptr<CSS1Expression> pExpr )
{
OSL_ENSURE( pItemSet, "DeclarationParsed() without ItemSet" );
@@ -3168,7 +3153,7 @@ void SvxCSS1Parser::ParseProperty( const OUString& rProperty,
CSS1PropEntryFindCompare );
if( it != std::end(aCSS1PropFnTab) && !CSS1PropEntryFindCompare(*it,rProperty) )
{
- it->pFunc( pExpr, *pItemSet, *pPropInfo, *this );
+ it->pFunc( pExpr.get(), *pItemSet, *pPropInfo, *this );
}
}
diff --git a/sw/source/filter/html/svxcss1.hxx b/sw/source/filter/html/svxcss1.hxx
index 2c1c70525146..fdc2b1a78a67 100644
--- a/sw/source/filter/html/svxcss1.hxx
+++ b/sw/source/filter/html/svxcss1.hxx
@@ -202,12 +202,7 @@ class SvxCSS1Parser : public CSS1Parser
static constexpr sal_uInt16 gnMinFixLineSpace = MM50/2; // minimum spacing for fixed line spacing
rtl_TextEncoding eDfltEnc;
-
bool bIgnoreFontFamily;
-
- void ParseProperty( const OUString& rProperty,
- const CSS1Expression *pExpr );
-
std::vector<sal_uInt16> aWhichMap; // Which-Map of Parser
using CSS1Parser::ParseStyleOption;
@@ -229,13 +224,13 @@ protected:
/// the content of the aItemSet will be copied into all recently
/// created Styles.
/// Derived classes should not override this method!
- virtual bool SelectorParsed( CSS1Selector *pSelector, bool bFirst ) override;
+ virtual void SelectorParsed( std::unique_ptr<CSS1Selector> pSelector, bool bFirst ) override;
/// Will be called for every parsed Property. Adds the item to the
/// pItemSet.
/// Derived classes should not override this method!
- virtual bool DeclarationParsed( const OUString& rProperty,
- const CSS1Expression *pExpr ) override;
+ virtual void DeclarationParsed( const OUString& rProperty,
+ std::unique_ptr<CSS1Expression> pExpr ) override;
public: