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

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Sat Jul 17 10:48:36 UTC 2021


 include/svtools/svparser.hxx      |    6 ----
 svtools/source/svrtf/svparser.cxx |   55 --------------------------------------
 sw/source/filter/html/svxcss1.cxx |   11 ++++++-
 sw/source/filter/html/svxcss1.hxx |    4 +-
 4 files changed, 11 insertions(+), 65 deletions(-)

New commits:
commit 1b80998025e13fbf71017ac08fa607737e716429
Author:     Noel Grandin <noelgrandin at gmail.com>
AuthorDate: Fri Jul 16 20:37:15 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sat Jul 17 12:48:05 2021 +0200

    move BuildWhichTable and simplify
    
    move it to the only place using it, and simplify
    
    Change-Id: I4a46b5d01f042e7b2e99b7dd1d28f67feda037d0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119086
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/svtools/svparser.hxx b/include/svtools/svparser.hxx
index 0941c4e6d99b..3233cf8000a7 100644
--- a/include/svtools/svparser.hxx
+++ b/include/svtools/svparser.hxx
@@ -141,12 +141,6 @@ public:
     T GetSaveToken() const;
 };
 
-// build a Which-Map 'rWhichMap' from an array of WhichIds
-// 'pWhichIds'. It has the length 'nWhichIds'.
-// The WhichMap is not deleted.
-SVT_DLLPUBLIC void BuildWhichTable( std::vector<sal_uInt16> &rWhichMap,
-                               sal_uInt16 const *pWhichIds,
-                               sal_uInt16 nWhichIds );
 
 /*========================================================================
  *
diff --git a/svtools/source/svrtf/svparser.cxx b/svtools/source/svrtf/svparser.cxx
index 301e2961d923..3da34404f517 100644
--- a/svtools/source/svrtf/svparser.cxx
+++ b/svtools/source/svrtf/svparser.cxx
@@ -595,61 +595,6 @@ void SvParser<T>::Continue( T )
 {
 }
 
-void BuildWhichTable( std::vector<sal_uInt16> &rWhichMap,
-                      sal_uInt16 const *pWhichIds,
-                      sal_uInt16 nWhichIds )
-{
-    sal_uInt16 aNewRange[2];
-
-    for( sal_uInt16 nCnt = 0; nCnt < nWhichIds; ++nCnt, ++pWhichIds )
-        if( *pWhichIds )
-        {
-            aNewRange[0] = aNewRange[1] = *pWhichIds;
-            bool bIns = true;
-
-            // search position
-            for ( sal_uInt16 nOfs = 0; rWhichMap[nOfs]; nOfs += 2 )
-            {
-                if( *pWhichIds < rWhichMap[nOfs] - 1 )
-                {
-                    // new range before
-                    rWhichMap.insert( rWhichMap.begin() + nOfs, aNewRange, aNewRange + 2 );
-                    bIns = false;
-                    break;
-                }
-                else if( *pWhichIds == rWhichMap[nOfs] - 1 )
-                {
-                    // extend range downwards
-                    rWhichMap[nOfs] = *pWhichIds;
-                    bIns = false;
-                    break;
-                }
-                else if( *pWhichIds == rWhichMap[nOfs+1] + 1 )
-                {
-                    if( rWhichMap[nOfs+2] != 0 && rWhichMap[nOfs+2] == *pWhichIds + 1 )
-                    {
-                        // merge with next field
-                        rWhichMap[nOfs+1] = rWhichMap[nOfs+3];
-                        rWhichMap.erase( rWhichMap.begin() + nOfs + 2,
-                                rWhichMap.begin() + nOfs + 4 );
-                    }
-                    else
-                        // extend range upwards
-                        rWhichMap[nOfs+1] = *pWhichIds;
-                    bIns = false;
-                    break;
-                }
-            }
-
-            // append range
-            if( bIns )
-            {
-                rWhichMap.insert( rWhichMap.begin() + rWhichMap.size() - 1,
-                        aNewRange, aNewRange + 2 );
-            }
-        }
-}
-
 
 // expanded out version of
 //   IMPL_LINK_NOARG( SvParser, NewDataRead, LinkParamNone*, void )
diff --git a/sw/source/filter/html/svxcss1.cxx b/sw/source/filter/html/svxcss1.cxx
index 280c927320d0..649163449d56 100644
--- a/sw/source/filter/html/svxcss1.cxx
+++ b/sw/source/filter/html/svxcss1.cxx
@@ -694,6 +694,14 @@ void SvxCSS1Parser::SelectorParsed( std::unique_ptr<CSS1Selector> pSelector, boo
     m_Selectors.push_back(std::move(pSelector));
 }
 
+static void BuildWhichTable( WhichRangesContainer& rWhichMap,
+                               sal_uInt16 const *pWhichIds,
+                               sal_uInt16 nWhichIds )
+{
+    for (sal_uInt16 i = 0; i < nWhichIds; ++i)
+        rWhichMap = rWhichMap.MergeRange(pWhichIds[i], pWhichIds[i]);
+}
+
 SvxCSS1Parser::SvxCSS1Parser( SfxItemPool& rPool, const OUString& rBaseURL,
                               sal_uInt16 const *pWhichIds, sal_uInt16 nWhichIds ) :
     CSS1Parser(),
@@ -740,13 +748,12 @@ SvxCSS1Parser::SvxCSS1Parser( SfxItemPool& rPool, const OUString& rBaseURL,
     aItemIds.nLanguageCTL = rPool.GetTrueWhich( SID_ATTR_CHAR_CTL_LANGUAGE, false );
     aItemIds.nDirection = rPool.GetTrueWhich( SID_ATTR_FRAMEDIRECTION, false );
 
-    m_aWhichMap.insert( m_aWhichMap.begin(), 0 );
     BuildWhichTable( m_aWhichMap, reinterpret_cast<sal_uInt16 *>(&aItemIds),
                              sizeof(aItemIds) / sizeof(sal_uInt16) );
     if( pWhichIds && nWhichIds )
         BuildWhichTable( m_aWhichMap, pWhichIds, nWhichIds );
 
-    m_pSheetItemSet.reset( new SfxItemSet( rPool, m_aWhichMap.data() ) );
+    m_pSheetItemSet.reset( new SfxItemSet( rPool, m_aWhichMap ) );
     m_pSheetPropInfo.reset( new SvxCSS1PropertyInfo );
 }
 
diff --git a/sw/source/filter/html/svxcss1.hxx b/sw/source/filter/html/svxcss1.hxx
index 2e0e14fd254a..fd547a0e9d76 100644
--- a/sw/source/filter/html/svxcss1.hxx
+++ b/sw/source/filter/html/svxcss1.hxx
@@ -206,7 +206,7 @@ class SvxCSS1Parser : public CSS1Parser
 
     rtl_TextEncoding    m_eDefaultEnc;
     bool m_bIgnoreFontFamily;
-    std::vector<sal_uInt16> m_aWhichMap;        // Which-Map of Parser
+    WhichRangesContainer m_aWhichMap;        // Which-Map of Parser
 
     using CSS1Parser::ParseStyleOption;
 
@@ -264,7 +264,7 @@ public:
 
     virtual const FontList *GetFontList() const;
 
-    const sal_uInt16 *GetWhichMap() const { return m_aWhichMap.data(); }
+    const WhichRangesContainer& GetWhichMap() const { return m_aWhichMap; }
 
     static void InsertMapEntry( const OUString& rKey, const SfxItemSet& rItemSet,
                          const SvxCSS1PropertyInfo& rProp, CSS1Map& rMap );


More information about the Libreoffice-commits mailing list