[Libreoffice-commits] core.git: 2 commits - sw/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Mon Jan 14 06:02:41 UTC 2019


 sw/source/filter/html/parcss1.cxx |   54 +++++++++++++++-----------------------
 sw/source/filter/html/parcss1.hxx |   12 +++-----
 sw/source/filter/html/svxcss1.cxx |   25 +++--------------
 sw/source/filter/html/svxcss1.hxx |   11 ++-----
 sw/source/filter/xml/xmlfmt.cxx   |    7 ++--
 5 files changed, 38 insertions(+), 71 deletions(-)

New commits:
commit 57cf9acfde03dd4247b4a40ca10bb3fd2f8bed17
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Fri Jan 11 15:27:27 2019 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Mon Jan 14 07:02:26 2019 +0100

    use unique_ptr in SwXMLItemSetStyleContext_Impl::ConnectPageDesc
    
    Change-Id: Ie633140acbb3254fb90056a601d58843cf8116cf
    Reviewed-on: https://gerrit.libreoffice.org/66187
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sw/source/filter/xml/xmlfmt.cxx b/sw/source/filter/xml/xmlfmt.cxx
index b9f584e5a672..35257d16dfdc 100644
--- a/sw/source/filter/xml/xmlfmt.cxx
+++ b/sw/source/filter/xml/xmlfmt.cxx
@@ -614,21 +614,20 @@ void SwXMLItemSetStyleContext_Impl::ConnectPageDesc()
     }
 
     const SfxPoolItem *pItem;
-    SwFormatPageDesc *pFormatPageDesc = nullptr;
+    std::unique_ptr<SwFormatPageDesc> pFormatPageDesc;
     if( SfxItemState::SET == pItemSet->GetItemState( RES_PAGEDESC, false,
                                                 &pItem ) )
     {
          if( static_cast<const SwFormatPageDesc *>(pItem)->GetPageDesc() != pPageDesc )
-            pFormatPageDesc = new SwFormatPageDesc( *static_cast<const SwFormatPageDesc *>(pItem) );
+            pFormatPageDesc.reset(new SwFormatPageDesc( *static_cast<const SwFormatPageDesc *>(pItem) ));
     }
     else
-        pFormatPageDesc = new SwFormatPageDesc();
+        pFormatPageDesc.reset(new SwFormatPageDesc());
 
     if( pFormatPageDesc )
     {
         pFormatPageDesc->RegisterToPageDesc( *pPageDesc );
         pItemSet->Put( *pFormatPageDesc );
-        delete pFormatPageDesc;
     }
 }
 
commit 0f257c1dce36b69741a96ec9c10158867c48f610
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Fri Jan 11 13:28:39 2019 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Mon Jan 14 07:02:20 2019 +0100

    use unique_ptr in CSS1Parser
    
    Change-Id: I4553233f7cf2f54a94154f41e899183490eec3e9
    Reviewed-on: https://gerrit.libreoffice.org/66184
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

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:
 


More information about the Libreoffice-commits mailing list