Add minimal INetMIME::scanContentType test and fix bugs thus found

Change-Id: I8fcbeb2b0804bc4f9ee8f97f7d02737ba79a7f20
diff --git a/tools/qa/cppunit/test_inetmime.cxx b/tools/qa/cppunit/test_inetmime.cxx
index 50973df..1a5d16b 100644
--- a/tools/qa/cppunit/test_inetmime.cxx
+++ b/tools/qa/cppunit/test_inetmime.cxx
@@ -35,8 +35,11 @@ namespace
    public:
        void test_decodeHeaderFieldBody();

        void test_scanContentType();

        CPPUNIT_TEST_SUITE(Test);
        CPPUNIT_TEST(test_decodeHeaderFieldBody);
        CPPUNIT_TEST(test_scanContentType);
        CPPUNIT_TEST_SUITE_END();
    };

@@ -53,6 +56,29 @@ namespace
        CPPUNIT_ASSERT(testDecode("=?iso-8859-1?B?QUJD?=", "ABC"));
    }

    void Test::test_scanContentType()
    {
        {
            OUString input
                = "TEST/subTST; parm1*0*=US-ASCII'En'5%25%20; Parm1*1*=of%2010";
            OUString type;
            OUString subType;
            INetContentTypeParameterList parameters;
            auto end = INetMIME::scanContentType(
                input.getStr(), input.getStr() + input.getLength(), &type,
                &subType, &parameters);
            CPPUNIT_ASSERT(end != nullptr);
            CPPUNIT_ASSERT_EQUAL(OUString(), OUString(end));
            CPPUNIT_ASSERT_EQUAL(OUString("test"), type);
            CPPUNIT_ASSERT_EQUAL(OUString("subtst"), subType);
            CPPUNIT_ASSERT_EQUAL(
                INetContentTypeParameterList::size_type(1), parameters.size());
            auto i = parameters.find("parm1");
            CPPUNIT_ASSERT(i != parameters.end());
            CPPUNIT_ASSERT_EQUAL(OUString("5% of 10"), i->second.m_sValue);
        }
    }

    CPPUNIT_TEST_SUITE_REGISTRATION(Test);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/tools/source/inet/inetmime.cxx b/tools/source/inet/inetmime.cxx
index 27cb185..da5dab7 100644
--- a/tools/source/inet/inetmime.cxx
+++ b/tools/source/inet/inetmime.cxx
@@ -434,16 +434,17 @@ void appendISO88591(OUString & rText, sal_Char const * pBegin,
Parameter ** ParameterList::find(const OString& rAttribute,
                                 sal_uInt32 nSection, bool & rPresent)
{
    rPresent = false;
    Parameter ** p = &m_pList;
    for (; *p; p = &(*p)->m_pNext)
    {
        sal_Int32 nCompare = rAttribute.compareTo((*p)->m_aAttribute);
        if (nCompare > 0)
            break;
            return &(*p)->m_pNext;
        else if (nCompare == 0)
        {
            if (nSection > (*p)->m_nSection)
                break;
                return &(*p)->m_pNext;
            else if (nSection == (*p)->m_nSection)
            {
                rPresent = true;
@@ -451,7 +452,6 @@ Parameter ** ParameterList::find(const OString& rAttribute,
            }
        }
    }
    rPresent = false;
    return p;
}

@@ -793,9 +793,11 @@ sal_Unicode const * scanParameters(sal_Unicode const * pBegin,
                INetMIMEOutputSink aSink;
                while (p != pEnd)
                {
                    sal_uInt32 nChar = INetMIME::getUTF32Character(p, pEnd);
                    auto q = p;
                    sal_uInt32 nChar = INetMIME::getUTF32Character(q, pEnd);
                    if (rtl::isAscii(nChar) && !isTokenChar(nChar))
                        break;
                    p = q;
                    if (nChar == '%' && p + 1 < pEnd)
                    {
                        int nWeight1 = INetMIME::getHexWeight(p[0]);