[Libreoffice-commits] core.git: writerfilter/source

Mike Kaganski (via logerrit) logerrit at kemper.freedesktop.org
Tue Sep 24 12:25:15 UTC 2019


 writerfilter/source/dmapper/StyleSheetTable.cxx |  308 +++++++++++-------------
 1 file changed, 146 insertions(+), 162 deletions(-)

New commits:
commit 41d0f5540208f7b86c91804631a141380c397a57
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Tue Sep 24 10:06:20 2019 +0200
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Tue Sep 24 14:23:54 2019 +0200

    Use initializer list instead of iterating an array to construct the map
    
    The map and set are made function-local statics instead of members, to
    only create them once (as comment says).
    
    This also fixes the problem with missing comma between "page number" and
    "TableNormal", which presumably had prevented all entries starting from
    "PageNumber" from working properly.
    
    Change-Id: Iddfefb05b1ffd00d16f189ddb5a679adf7561aa6
    Reviewed-on: https://gerrit.libreoffice.org/79430
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
    Tested-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/writerfilter/source/dmapper/StyleSheetTable.cxx b/writerfilter/source/dmapper/StyleSheetTable.cxx
index 825f1511b60b..fbe8a60680e0 100644
--- a/writerfilter/source/dmapper/StyleSheetTable.cxx
+++ b/writerfilter/source/dmapper/StyleSheetTable.cxx
@@ -273,9 +273,6 @@ struct StyleSheetTable_Impl
     std::vector< StyleSheetEntryPtr >       m_aStyleSheetEntries;
     StyleSheetEntryPtr                      m_pCurrentEntry;
     PropertyMapPtr                          m_pDefaultParaProps, m_pDefaultCharProps;
-    StringPairMap_t                         m_aStyleNameMap;
-    /// Style names which should not be used without a " (user)" suffix.
-    std::set<OUString>                      m_aReservedStyleNames;
     OUString                                m_sDefaultParaStyleName; //WW8 name
     ListCharStylePropertyVector_t           m_aListCharStylePropertyVector;
     bool                                    m_bHasImportedDefaultParaProps;
@@ -1265,147 +1262,6 @@ const StyleSheetEntryPtr & StyleSheetTable::GetCurrentEntry()
     return m_pImpl->m_pCurrentEntry;
 }
 
-
-static const sal_Char* const aStyleNamePairs[] =
-{
-    "Normal",                     "Standard",
-    "heading 1",                  "Heading 1",
-    "heading 2",                  "Heading 2",
-    "heading 3",                  "Heading 3",
-    "heading 4",                  "Heading 4",
-    "heading 5",                  "Heading 5",
-    "heading 6",                  "Heading 6",
-    "heading 7",                  "Heading 7",
-    "heading 8",                  "Heading 8",
-    "heading 9",                  "Heading 9",
-    "Heading 1",                  "Heading 1",
-    "Heading 2",                  "Heading 2",
-    "Heading 3",                  "Heading 3",
-    "Heading 4",                  "Heading 4",
-    "Heading 5",                  "Heading 5",
-    "Heading 6",                  "Heading 6",
-    "Heading 7",                  "Heading 7",
-    "Heading 8",                  "Heading 8",
-    "Heading 9",                  "Heading 9",
-    "Index 1",                   "Index 1",
-    "Index 2",                   "Index 2",
-    "Index 3",                   "Index 3",
-    "Index 4",                   "",
-    "Index 5",                   "",
-    "Index 6",                   "",
-    "Index 7",                   "",
-    "Index 8",                   "",
-    "Index 9",                   "",
-    "TOC 1",                     "Contents 1",
-    "TOC 2",                     "Contents 2",
-    "TOC 3",                     "Contents 3",
-    "TOC 4",                     "Contents 4",
-    "TOC 5",                     "Contents 5",
-    "TOC 6",                     "Contents 6",
-    "TOC 7",                     "Contents 7",
-    "TOC 8",                     "Contents 8",
-    "TOC 9",                     "Contents 9",
-    "TOCHeading",                "Contents Heading",
-    "toc 1",                     "Contents 1",
-    "toc 2",                     "Contents 2",
-    "toc 3",                     "Contents 3",
-    "toc 4",                     "Contents 4",
-    "toc 5",                     "Contents 5",
-    "toc 6",                     "Contents 6",
-    "toc 7",                     "Contents 7",
-    "toc 8",                     "Contents 8",
-    "toc 9",                     "Contents 9",
-    "TOC1",                     "Contents 1",
-    "TOC2",                     "Contents 2",
-    "TOC3",                     "Contents 3",
-    "TOC4",                     "Contents 4",
-    "TOC5",                     "Contents 5",
-    "TOC6",                     "Contents 6",
-    "TOC7",                     "Contents 7",
-    "TOC8",                     "Contents 8",
-    "TOC9",                     "Contents 9",
-    "Normal Indent",             "",
-    "footnote text",             "Footnote",
-    "Footnote Text",             "Footnote",
-    "Annotation Text",           "",
-    "Header",                    "Header",
-    "header",                    "Header",
-    "Footer",                    "Footer",
-    "footer",                    "Footer",
-    "Index Heading",             "Index Heading",
-    "Caption",                   "",
-    "Table of Figures",          "",
-    "Envelope Address",          "Addressee",
-    "Envelope Return",           "Sender",
-    "footnote reference",        "Footnote Characters",
-    "Footnote Reference",        "Footnote Characters",
-    "Annotation Reference",      "",
-    "Line Number",               "Line numbering",
-    "Page Number",               "Page Number",
-    "endnote reference",         "Endnote Characters",
-    "Endnote Reference",         "Endnote Characters",
-    "endnote text",              "Endnote",
-    "Endnote Text",              "Endnote",
-    "Table of Authorities",      "",
-    "Macro Text",                "",
-    "TOA Heading",               "",
-    "List",                      "List",
-    "List 2",                    "",
-    "List 3",                    "",
-    "List 4",                    "",
-    "List 5",                    "",
-    "List Bullet",               "",
-    "List Bullet 2",             "",
-    "List Bullet 3",             "",
-    "List Bullet 4",             "",
-    "List Bullet 5",             "",
-    "List Number",               "",
-    "List Number 2",             "",
-    "List Number 3",             "",
-    "List Number 4",             "",
-    "List Number 5",             "",
-    "Title",                     "Title",
-    "Closing",                   "",
-    "Signature",                 "Signature",
-    "Default Paragraph Font",    "",
-    "DefaultParagraphFont",      "Default Paragraph Font",
-    "Body Text",                 "Text body",
-    "BodyText",                  "Text body",
-    "BodyTextIndentItalic",     "Text body indent italic",
-    "Body Text Indent",          "Text body indent",
-    "BodyTextIndent",           "Text body indent",
-    "BodyTextIndent2",          "Text body indent2",
-    "List Continue",             "",
-    "List Continue 2",           "",
-    "List Continue 3",           "",
-    "List Continue 4",           "",
-    "List Continue 5",           "",
-    "Message Header",            "",
-    "Subtitle",                  "Subtitle",
-    "Salutation",                "",
-    "Date",                      "",
-    "Body Text First Indent",    "Body Text Indent",
-    "Body Text First Indent 2",  "",
-    "Note Heading",              "",
-    "Body Text 2",               "",
-    "Body Text 3",               "",
-    "Body Text Indent 2",        "",
-    "Body Text Indent 3",        "",
-    "Block Text",                "",
-    "Hyperlink",                 "Internet link",
-    "Followed Hyperlink",        "Visited Internet Link",
-    "Emphasis",                  "Emphasis",
-    "Document Map",              "",
-    "Plain Text",                "",
-    "NoList",                   "No List",
-    "AbstractHeading",          "Abstract Heading",
-    "AbstractBody",             "Abstract Body",
-    "PageNumber",               "page number"
-    "TableNormal",              "Normal Table",
-    "DocumentMap",              "Document Map"
-};
-
-
 OUString StyleSheetTable::ConvertStyleName( const OUString& rWWName, bool bExtendedSearch)
 {
     OUString sRet( rWWName );
@@ -1421,33 +1277,161 @@ OUString StyleSheetTable::ConvertStyleName( const OUString& rWWName, bool bExten
     }
 
     // create a map only once
-    if(m_pImpl->m_aStyleNameMap.empty())
-    {
-        for( size_t nPair = 0; nPair < SAL_N_ELEMENTS(aStyleNamePairs)/2; ++nPair)
-        {
-            OUString aFrom = OUString::createFromAscii(aStyleNamePairs[2 * nPair]);
-            OUString aTo = OUString::createFromAscii(aStyleNamePairs[2 * nPair + 1]);
-            if (!aTo.isEmpty())
-            {
-                m_pImpl->m_aStyleNameMap.emplace(aFrom, aTo);
-                m_pImpl->m_aReservedStyleNames.insert(aTo);
-            }
-        }
-    }
+    static const StringPairMap_t StyleNameMap{
+        { "Normal", "Standard" },
+        { "heading 1", "Heading 1" },
+        { "heading 2", "Heading 2" },
+        { "heading 3", "Heading 3" },
+        { "heading 4", "Heading 4" },
+        { "heading 5", "Heading 5" },
+        { "heading 6", "Heading 6" },
+        { "heading 7", "Heading 7" },
+        { "heading 8", "Heading 8" },
+        { "heading 9", "Heading 9" },
+        { "Heading 1", "Heading 1" },
+        { "Heading 2", "Heading 2" },
+        { "Heading 3", "Heading 3" },
+        { "Heading 4", "Heading 4" },
+        { "Heading 5", "Heading 5" },
+        { "Heading 6", "Heading 6" },
+        { "Heading 7", "Heading 7" },
+        { "Heading 8", "Heading 8" },
+        { "Heading 9", "Heading 9" },
+        { "Index 1", "Index 1" },
+        { "Index 2", "Index 2" },
+        { "Index 3", "Index 3" },
+//        { "Index 4", "" },
+//        { "Index 5", "" },
+//        { "Index 6", "" },
+//        { "Index 7", "" },
+//        { "Index 8", "" },
+//        { "Index 9", "" },
+        { "TOC 1", "Contents 1" },
+        { "TOC 2", "Contents 2" },
+        { "TOC 3", "Contents 3" },
+        { "TOC 4", "Contents 4" },
+        { "TOC 5", "Contents 5" },
+        { "TOC 6", "Contents 6" },
+        { "TOC 7", "Contents 7" },
+        { "TOC 8", "Contents 8" },
+        { "TOC 9", "Contents 9" },
+        { "TOCHeading", "Contents Heading" },
+        { "toc 1", "Contents 1" },
+        { "toc 2", "Contents 2" },
+        { "toc 3", "Contents 3" },
+        { "toc 4", "Contents 4" },
+        { "toc 5", "Contents 5" },
+        { "toc 6", "Contents 6" },
+        { "toc 7", "Contents 7" },
+        { "toc 8", "Contents 8" },
+        { "toc 9", "Contents 9" },
+        { "TOC1", "Contents 1" },
+        { "TOC2", "Contents 2" },
+        { "TOC3", "Contents 3" },
+        { "TOC4", "Contents 4" },
+        { "TOC5", "Contents 5" },
+        { "TOC6", "Contents 6" },
+        { "TOC7", "Contents 7" },
+        { "TOC8", "Contents 8" },
+        { "TOC9", "Contents 9" },
+//        { "Normal Indent", "" },
+        { "footnote text", "Footnote" },
+        { "Footnote Text", "Footnote" },
+//        { "Annotation Text", "" },
+        { "Header", "Header" },
+        { "header", "Header" },
+        { "Footer", "Footer" },
+        { "footer", "Footer" },
+        { "Index Heading", "Index Heading" },
+//        { "Caption", "" },
+//        { "Table of Figures", "" },
+        { "Envelope Address", "Addressee" },
+        { "Envelope Return", "Sender" },
+        { "footnote reference", "Footnote Characters" },
+        { "Footnote Reference", "Footnote Characters" },
+//        { "Annotation Reference", "" },
+        { "Line Number", "Line numbering" },
+        { "Page Number", "Page Number" },
+        { "endnote reference", "Endnote Characters" },
+        { "Endnote Reference", "Endnote Characters" },
+        { "endnote text", "Endnote" },
+        { "Endnote Text", "Endnote" },
+//        { "Table of Authorities", "" },
+//        { "Macro Text", "" },
+//        { "TOA Heading", "" },
+        { "List", "List" },
+//        { "List 2", "" },
+//        { "List 3", "" },
+//        { "List 4", "" },
+//        { "List 5", "" },
+//        { "List Bullet", "" },
+//        { "List Bullet 2", "" },
+//        { "List Bullet 3", "" },
+//        { "List Bullet 4", "" },
+//        { "List Bullet 5", "" },
+//        { "List Number", "" },
+//        { "List Number 2", "" },
+//        { "List Number 3", "" },
+//        { "List Number 4", "" },
+//        { "List Number 5", "" },
+        { "Title", "Title" },
+//        { "Closing", "" },
+        { "Signature", "Signature" },
+//        { "Default Paragraph Font", "" },
+        { "DefaultParagraphFont", "Default Paragraph Font" },
+        { "Body Text", "Text body" },
+        { "BodyText", "Text body" },
+        { "BodyTextIndentItalic", "Text body indent italic" },
+        { "Body Text Indent", "Text body indent" },
+        { "BodyTextIndent", "Text body indent" },
+        { "BodyTextIndent2", "Text body indent2" },
+//        { "List Continue", "" },
+//        { "List Continue 2", "" },
+//        { "List Continue 3", "" },
+//        { "List Continue 4", "" },
+//        { "List Continue 5", "" },
+//        { "Message Header", "" },
+        { "Subtitle", "Subtitle" },
+//        { "Salutation", "" },
+//        { "Date", "" },
+        { "Body Text First Indent", "Body Text Indent" },
+//        { "Body Text First Indent 2", "" },
+//        { "Note Heading", "" },
+//        { "Body Text 2", "" },
+//        { "Body Text 3", "" },
+//        { "Body Text Indent 2", "" },
+//        { "Body Text Indent 3", "" },
+//        { "Block Text", "" },
+        { "Hyperlink", "Internet link" },
+        { "Followed Hyperlink", "Visited Internet Link" },
+        { "Emphasis", "Emphasis" },
+//        { "Document Map", "" },
+//        { "Plain Text", "" },
+        { "NoList", "No List" },
+        { "AbstractHeading", "Abstract Heading" },
+        { "AbstractBody", "Abstract Body" },
+        { "PageNumber", "page number" },
+        { "TableNormal", "Normal Table" },
+        { "DocumentMap", "Document Map" },
+    };
 
     // find style-name using map
-    StringPairMap_t::iterator aIt = m_pImpl->m_aStyleNameMap.find( sRet );
-
-    if (aIt != m_pImpl->m_aStyleNameMap.end())
+    if (const auto aIt = StyleNameMap.find(sRet); aIt != StyleNameMap.end())
     {
         sRet = aIt->second;
     }
     else
     {
+        // Style names which should not be used without a " (user)" suffix
+        static const std::set<OUString> ReservedStyleNames = [] {
+            std::set<OUString> set;
+            for (const auto& pair : StyleNameMap)
+                set.insert(pair.second);
+            return set;
+        }();
         // SwStyleNameMapper doc says: If the UI style name equals a
         // programmatic name, then it must append " (user)" to the end.
-        std::set<OUString>::iterator aReservedIt = m_pImpl->m_aReservedStyleNames.find(sRet);
-        if (aReservedIt != m_pImpl->m_aReservedStyleNames.end())
+        if (ReservedStyleNames.count(sRet) > 0)
             sRet += " (user)";
     }
 


More information about the Libreoffice-commits mailing list