[Libreoffice-commits] core.git: desktop/source include/tools svl/qa svtools/source tools/source

Michael Stahl mstahl at redhat.com
Thu Jul 16 04:48:43 PDT 2015


 desktop/source/deployment/manager/dp_manager.cxx              |    5 
 desktop/source/deployment/registry/component/dp_component.cxx |   22 -
 desktop/source/deployment/registry/package/dp_package.cxx     |   11 
 include/tools/inetmime.hxx                                    |  163 +++++-----
 svl/qa/unit/test_INetContentType.cxx                          |   12 
 svtools/source/svhtml/parhtml.cxx                             |    5 
 tools/source/inet/inetmime.cxx                                |   29 -
 7 files changed, 119 insertions(+), 128 deletions(-)

New commits:
commit 21834f14c97071c5bcf13ef02bf940dc1922663f
Author: Michael Stahl <mstahl at redhat.com>
Date:   Wed Jul 15 23:17:20 2015 +0200

    tools: replace boost::ptr_vector with std::unordered_map
    
    Change-Id: I530c5f95dda9aa80654e3a2a20a2e236221e7305

diff --git a/desktop/source/deployment/manager/dp_manager.cxx b/desktop/source/deployment/manager/dp_manager.cxx
index 3392b54..d67f496 100644
--- a/desktop/source/deployment/manager/dp_manager.cxx
+++ b/desktop/source/deployment/manager/dp_manager.cxx
@@ -971,9 +971,8 @@ Reference<deployment::XPackage> PackageManagerImpl::getDeployedPackage_(
         INetContentTypeParameterList params;
         if (INetContentTypes::parse( data.mediaType, type, subType, &params ))
         {
-            INetContentTypeParameter const * param = params.find(
-                OString("platform") );
-            if (param != 0 && !platform_fits( param->m_sValue ))
+            auto const iter = params.find(OString("platform"));
+            if (iter != params.end() && !platform_fits(iter->second.m_sValue))
                 throw lang::IllegalArgumentException(
                     getResourceString(RID_STR_NO_SUCH_PACKAGE) + id,
                     static_cast<OWeakObject *>(this),
diff --git a/desktop/source/deployment/registry/component/dp_component.cxx b/desktop/source/deployment/registry/component/dp_component.cxx
index e17961f..9b2a2a7 100644
--- a/desktop/source/deployment/registry/component/dp_component.cxx
+++ b/desktop/source/deployment/registry/component/dp_component.cxx
@@ -670,21 +670,21 @@ Reference<deployment::XPackage> BackendImpl::bindPackage_(
             {
                 // xxx todo: probe and evaluate component xml description
 
-                INetContentTypeParameter const * param = params.find(OString("platform"));
-                bool bPlatformFits(param == 0);
+                auto const iter = params.find(OString("platform"));
+                bool bPlatformFits(iter == params.end());
                 OUString aPlatform;
                 if (!bPlatformFits) // platform is specified, we have to check
                 {
-                    aPlatform = param->m_sValue;
+                    aPlatform = iter->second.m_sValue;
                     bPlatformFits = platform_fits(aPlatform);
                 }
                 // If the package is being removed, do not care whether
                 // platform fits. We won't be using it anyway.
                 if (bPlatformFits || bRemoved) {
-                    param = params.find(OString("type"));
-                    if (param != 0)
+                    auto const iterType = params.find(OString("type"));
+                    if (iterType != params.end())
                     {
-                        OUString const & value = param->m_sValue;
+                        OUString const & value = iterType->second.m_sValue;
                         if (value.equalsIgnoreAsciiCase("native")) {
                             if (bPlatformFits)
                                 return new BackendImpl::ComponentPackageImpl(
@@ -713,8 +713,8 @@ Reference<deployment::XPackage> BackendImpl::bindPackage_(
             }
             else if (subType.equalsIgnoreAsciiCase("vnd.sun.star.uno-components"))
             {
-                INetContentTypeParameter const * param = params.find(OString("platform"));
-                if (param == 0 || platform_fits( param->m_sValue )) {
+                auto const iter = params.find(OString("platform"));
+                if (iter == params.end() || platform_fits(iter->second.m_sValue)) {
                     return new BackendImpl::ComponentsPackageImpl(
                         this, url, name, m_xComponentsTypeInfo, bRemoved,
                         identifier);
@@ -722,9 +722,9 @@ Reference<deployment::XPackage> BackendImpl::bindPackage_(
             }
             else if (subType.equalsIgnoreAsciiCase( "vnd.sun.star.uno-typelibrary"))
             {
-                INetContentTypeParameter const * param = params.find(OString("type"));
-                if (param != 0) {
-                    OUString const & value = param->m_sValue;
+                auto const iter = params.find(OString("type"));
+                if (iter != params.end()) {
+                    OUString const & value = iter->second.m_sValue;
                     if (value.equalsIgnoreAsciiCase("RDB"))
                     {
                         return new BackendImpl::TypelibraryPackageImpl(
diff --git a/desktop/source/deployment/registry/package/dp_package.cxx b/desktop/source/deployment/registry/package/dp_package.cxx
index db08cb9..2ce790d 100644
--- a/desktop/source/deployment/registry/package/dp_package.cxx
+++ b/desktop/source/deployment/registry/package/dp_package.cxx
@@ -1473,8 +1473,8 @@ void BackendImpl::PackageImpl::scanBundle(
         if (! INetContentTypes::parse( mediaType, type, subType, &params ))
             continue;
 
-        INetContentTypeParameter const * param = params.find("platform");
-        if (param != 0 && !platform_fits( param->m_sValue ))
+        auto const iter = params.find("platform");
+        if (iter != params.end() && !platform_fits(iter->second.m_sValue))
             continue;
         const OUString url( makeURL( packageRootURL, fullPath ) );
 
@@ -1483,14 +1483,15 @@ void BackendImpl::PackageImpl::scanBundle(
             subType.equalsIgnoreAsciiCase( "vnd.sun.star.package-bundle-description"))
         {
             // check locale:
-            param = params.find("locale");
-            if (param == 0) {
+            auto const iterLocale = params.find("locale");
+            if (iterLocale == params.end())
+            {
                 if (descrFile.isEmpty())
                     descrFile = url;
             }
             else {
                 // match best locale:
-                LanguageTag descrTag( param->m_sValue);
+                LanguageTag descrTag(iter->second.m_sValue);
                 if (officeLocale.getLanguage() == descrTag.getLanguage())
                 {
                     size_t nPenalty = nPenaltyMax;
diff --git a/include/tools/inetmime.hxx b/include/tools/inetmime.hxx
index 5766660..1e7672c 100644
--- a/include/tools/inetmime.hxx
+++ b/include/tools/inetmime.hxx
@@ -19,8 +19,6 @@
 #ifndef INCLUDED_TOOLS_INETMIME_HXX
 #define INCLUDED_TOOLS_INETMIME_HXX
 
-#include <boost/ptr_container/ptr_vector.hpp>
-
 #include <tools/toolsdllapi.h>
 #include <rtl/alloc.h>
 #include <rtl/character.hxx>
@@ -31,11 +29,96 @@
 #include <tools/debug.hxx>
 #include <tools/errcode.hxx>
 
+#include <unordered_map>
+
 class DateTime;
-class INetContentTypeParameterList;
 class INetMIMECharsetList_Impl;
 class INetMIMEOutputSink;
 
+struct INetContentTypeParameter
+{
+    /** The name of the attribute, in US-ASCII encoding and converted to lower
+        case.  If a parameter value is split as described in RFC 2231, there
+        will only be one item for the complete parameter, with the attribute
+        name lacking any section suffix.
+     */
+#ifndef _LIBCPP_VERSION
+    const
+#endif
+          OString m_sAttribute;
+
+    /** The optional character set specification (see RFC 2231), in US-ASCII
+        encoding and converted to lower case.
+     */
+#ifndef _LIBCPP_VERSION
+    const
+#endif
+          OString m_sCharset;
+
+    /** The optional language specification (see RFC 2231), in US-ASCII
+        encoding and converted to lower case.
+     */
+#ifndef _LIBCPP_VERSION
+    const
+#endif
+          OString m_sLanguage;
+
+    /** The attribute value.  If the value is a quoted-string, it is
+        'unpacked.'  If a character set is specified, and the value can be
+        converted to Unicode, this is done.  Also, if no character set is
+        specified, it is first tried to convert the value from UTF-8 encoding
+        to Unicode, and if that doesn't work (because the value is not in
+        UTF-8 encoding), it is converted from ISO-8859-1 encoding to Unicode
+        (which will always work).  But if a character set is specified and the
+        value cannot be converted from that character set to Unicode, special
+        action is taken to produce a value that can possibly be transformed
+        back into its original form:  Any 8-bit character from a non-encoded
+        part of the original value is directly converted to Unicode
+        (effectively handling it as if it was ISO-8859-1 encoded), and any
+        8-bit character from an encoded part of the original value is mapped
+        to the range U+F800..U+F8FF at the top of the Corporate Use Subarea
+        within Unicode's Private Use Area (effectively adding 0xF800 to the
+        character's numeric value).
+     */
+#ifndef _LIBCPP_VERSION
+    const
+#endif
+          OUString m_sValue;
+
+    /** This is true if the value is successfully converted to Unicode, and
+        false if the value is a special mixture of ISO-LATIN-1 characters and
+        characters from Unicode's Private Use Area.
+     */
+#ifndef _LIBCPP_VERSION
+    const
+#endif
+          bool m_bConverted;
+
+    INetContentTypeParameter(const OString& rTheAttribute,
+        const OString& rTheCharset, const OString& rTheLanguage,
+        const OUString& rTheValue, bool bTheConverted)
+    : m_sAttribute(rTheAttribute)
+    , m_sCharset(rTheCharset)
+    , m_sLanguage(rTheLanguage)
+    , m_sValue(rTheValue)
+    , m_bConverted(bTheConverted)
+    {
+    }
+};
+
+struct OString_equalsIgnoreAsciiCase
+{
+    bool operator()(const OString& r1, const OString& r2) const
+    {
+        return r1.equalsIgnoreAsciiCase(r2);
+    }
+};
+
+// the key is the m_sAttribute again
+typedef std::unordered_map<OString, INetContentTypeParameter, OStringHash,
+            OString_equalsIgnoreAsciiCase> INetContentTypeParameterList;
+
+
 class TOOLS_DLLPUBLIC INetMIME
 {
 public:
@@ -935,80 +1018,6 @@ inline bool INetMIMEEncodedWordOutputSink::flush()
     return m_ePrevCoding != CODING_NONE;
 }
 
-struct INetContentTypeParameter
-{
-    /** The name of the attribute, in US-ASCII encoding and converted to lower
-        case.  If a parameter value is split as described in RFC 2231, there
-        will only be one item for the complete parameter, with the attribute
-        name lacking any section suffix.
-     */
-    const OString m_sAttribute;
-
-    /** The optional character set specification (see RFC 2231), in US-ASCII
-        encoding and converted to lower case.
-     */
-    const OString m_sCharset;
-
-    /** The optional language specification (see RFC 2231), in US-ASCII
-        encoding and converted to lower case.
-     */
-    const OString m_sLanguage;
-
-    /** The attribute value.  If the value is a quoted-string, it is
-        'unpacked.'  If a character set is specified, and the value can be
-        converted to Unicode, this is done.  Also, if no character set is
-        specified, it is first tried to convert the value from UTF-8 encoding
-        to Unicode, and if that doesn't work (because the value is not in
-        UTF-8 encoding), it is converted from ISO-8859-1 encoding to Unicode
-        (which will always work).  But if a character set is specified and the
-        value cannot be converted from that character set to Unicode, special
-        action is taken to produce a value that can possibly be transformed
-        back into its original form:  Any 8-bit character from a non-encoded
-        part of the original value is directly converted to Unicode
-        (effectively handling it as if it was ISO-8859-1 encoded), and any
-        8-bit character from an encoded part of the original value is mapped
-        to the range U+F800..U+F8FF at the top of the Corporate Use Subarea
-        within Unicode's Private Use Area (effectively adding 0xF800 to the
-        character's numeric value).
-     */
-    const OUString m_sValue;
-
-    /** This is true if the value is successfully converted to Unicode, and
-        false if the value is a special mixture of ISO-LATIN-1 characters and
-        characters from Unicode's Private Use Area.
-     */
-    const bool m_bConverted;
-
-    INetContentTypeParameter(const OString& rTheAttribute,
-        const OString& rTheCharset, const OString& rTheLanguage,
-        const OUString& rTheValue, bool bTheConverted)
-    : m_sAttribute(rTheAttribute)
-    , m_sCharset(rTheCharset)
-    , m_sLanguage(rTheLanguage)
-    , m_sValue(rTheValue)
-    , m_bConverted(bTheConverted)
-    {
-    }
-};
-
-class TOOLS_DLLPUBLIC INetContentTypeParameterList
-{
-public:
-
-    void Clear();
-
-    void Append(INetContentTypeParameter *pParameter)
-    {
-        maEntries.push_back(pParameter);
-    }
-
-    const INetContentTypeParameter * find(const OString& rAttribute) const;
-
-private:
-
-    boost::ptr_vector<INetContentTypeParameter> maEntries;
-};
-
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svl/qa/unit/test_INetContentType.cxx b/svl/qa/unit/test_INetContentType.cxx
index b7aa71c..68badb6 100644
--- a/svl/qa/unit/test_INetContentType.cxx
+++ b/svl/qa/unit/test_INetContentType.cxx
@@ -48,8 +48,7 @@ void Test::testBad() {
     CPPUNIT_ASSERT(!INetContentTypes::parse(in, t, s, &ps));
     CPPUNIT_ASSERT(t.isEmpty());
     CPPUNIT_ASSERT(s.isEmpty());
-    CPPUNIT_ASSERT_EQUAL(
-        static_cast<INetContentTypeParameter const *>(0), ps.find("foo"));
+    CPPUNIT_ASSERT(ps.end() == ps.find("foo"));
 }
 
 void Test::testFull() {
@@ -63,9 +62,9 @@ void Test::testFull() {
     CPPUNIT_ASSERT(INetContentTypes::parse(in, t, s, &ps));
     CPPUNIT_ASSERT_EQUAL(OUString("foo"), t);
     CPPUNIT_ASSERT_EQUAL(OUString("bar"), s);
-    INetContentTypeParameter const * p = ps.find("baz");
-    CPPUNIT_ASSERT(p != 0);
-    CPPUNIT_ASSERT_EQUAL(OUString("boz"), p->m_sValue);
+    auto iter = ps.find("baz");
+    CPPUNIT_ASSERT(iter != ps.end());
+    CPPUNIT_ASSERT_EQUAL(OUString("boz"), iter->second.m_sValue);
 }
 
 void Test::testFollow() {
@@ -79,8 +78,7 @@ void Test::testFollow() {
     CPPUNIT_ASSERT(!INetContentTypes::parse(in, t, s));
     CPPUNIT_ASSERT(t.isEmpty());
     CPPUNIT_ASSERT(s.isEmpty());
-    CPPUNIT_ASSERT_EQUAL(
-        static_cast<INetContentTypeParameter const *>(0), ps.find("baz"));
+    CPPUNIT_ASSERT(ps.end() == ps.find("baz"));
 }
 
 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
diff --git a/svtools/source/svhtml/parhtml.cxx b/svtools/source/svhtml/parhtml.cxx
index 0158436..2627bc1 100644
--- a/svtools/source/svhtml/parhtml.cxx
+++ b/svtools/source/svhtml/parhtml.cxx
@@ -2092,9 +2092,10 @@ rtl_TextEncoding HTMLParser::GetEncodingByMIME( const OUString& rMime )
     INetContentTypeParameterList aParameters;
     if (INetContentTypes::parse(rMime, sType, sSubType, &aParameters))
     {
-        const INetContentTypeParameter * pCharset = aParameters.find("charset");
-        if (pCharset != 0)
+        auto const iter = aParameters.find("charset");
+        if (iter != aParameters.end())
         {
+            const INetContentTypeParameter * pCharset = &iter->second;
             OString sValue(OUStringToOString(pCharset->m_sValue, RTL_TEXTENCODING_ASCII_US));
             return GetExtendedCompatibilityTextEncoding( rtl_getTextEncodingFromMimeCharset( sValue.getStr() ) );
         }
diff --git a/tools/source/inet/inetmime.cxx b/tools/source/inet/inetmime.cxx
index bfb06b8..88e2cf9 100644
--- a/tools/source/inet/inetmime.cxx
+++ b/tools/source/inet/inetmime.cxx
@@ -257,7 +257,7 @@ bool parseParameters(ParameterList const & rInput,
                      INetContentTypeParameterList * pOutput)
 {
     if (pOutput)
-        pOutput->Clear();
+        pOutput->clear();
 
     Parameter * pPrev = 0;
     for (Parameter * p = rInput.m_pList; p; p = p->m_pNext)
@@ -335,11 +335,14 @@ bool parseParameters(ParameterList const & rInput,
                         break;
                 };
             }
-            pOutput->Append(new INetContentTypeParameter(p->m_aAttribute,
+            auto const ret = pOutput->insert(std::make_pair(p->m_aAttribute,
+                                    INetContentTypeParameter(p->m_aAttribute,
                                                              p->m_aCharset,
                                                              p->m_aLanguage,
                                                              aValue,
-                                                             !bBadEncoding));
+                                                             !bBadEncoding)));
+            SAL_INFO_IF(!ret.second, "tools",
+                "INetMIME: dropping duplicate parameter: " << p->m_aAttribute);
             p = pNext;
         }
     return true;
@@ -3738,24 +3741,4 @@ INetMIMEEncodedWordOutputSink::WriteUInt32(sal_uInt32 nChar)
     return *this;
 }
 
-//  INetContentTypeParameterList
-
-void INetContentTypeParameterList::Clear()
-{
-    maEntries.clear();
-}
-
-const INetContentTypeParameter *
-INetContentTypeParameterList::find(const OString& rAttribute) const
-{
-    boost::ptr_vector<INetContentTypeParameter>::const_iterator iter;
-    for (iter = maEntries.begin(); iter != maEntries.end(); ++iter)
-    {
-        if (iter->m_sAttribute.equalsIgnoreAsciiCase(rAttribute))
-            return &(*iter);
-    }
-
-    return NULL;
-}
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list