ofz#9917 use a WW8SprmIter to find the sprm

extend WW8SprmIter to support the needed paramater match feature and
drop the custom WW8PLCFx_SEPX::HasSprm logic

Change-Id: I5893e04402ed03493add398f0939a578807561ef
Reviewed-on: https://gerrit.libreoffice.org/59118
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/sw/source/filter/ww8/ww8scan.cxx b/sw/source/filter/ww8/ww8scan.cxx
index 98365be..563f262 100644
--- a/sw/source/filter/ww8/ww8scan.cxx
+++ b/sw/source/filter/ww8/ww8scan.cxx
@@ -918,7 +918,7 @@ void WW8SprmIter::UpdateMyMembers()
    }
}

SprmResult WW8SprmIter::FindSprm(sal_uInt16 nId)
SprmResult WW8SprmIter::FindSprm(sal_uInt16 nId, sal_uInt8* pNextByteMatch)
{
    while (GetSprms())
    {
@@ -926,7 +926,13 @@ SprmResult WW8SprmIter::FindSprm(sal_uInt16 nId)
        {
            sal_uInt16 nFixedLen =  mrSprmParser.DistanceToData(nId);
            sal_uInt16 nL = mrSprmParser.GetSprmSize(nId, GetSprms(), GetRemLen());
            return SprmResult(GetCurrentParams(), nL - nFixedLen); // SPRM found!
            SprmResult aRet(GetCurrentParams(), nL - nFixedLen); // SPRM found!
            // typically pNextByteMatch is nullptr and we just return the first match
            if (!pNextByteMatch)
                return aRet;
            // very occasionally we want one with a specific following byte
            if (aRet.nRemainingData >= 1 && *aRet.pSprm == *pNextByteMatch)
                return aRet;
        }
        advance();
    }
@@ -3844,32 +3850,13 @@ bool WW8PLCFx_SEPX::Find4Sprms(sal_uInt16 nId1,sal_uInt16 nId2,sal_uInt16 nId3,s

SprmResult WW8PLCFx_SEPX::HasSprm( sal_uInt16 nId, sal_uInt8 n2nd ) const
{
    if (!pPLCF)
        return SprmResult();

    sal_uInt8* pSp = pSprms.get();
    size_t i = 0;
    while (i + maSprmParser.MinSprmLen() <= nSprmSiz)
    SprmResult aRet;
    if (pPLCF)
    {
        // Sprm found?
        const sal_uInt16 nCurrentId = maSprmParser.GetSprmId(pSp);
        const sal_uInt16 x = maSprmParser.GetSprmSize(nCurrentId, pSp, nSprmSiz - i);
        if (nCurrentId == nId)
        {
            sal_uInt16 nFixedLen =  maSprmParser.DistanceToData(nId);
            const sal_uInt8 *pRet = pSp + nFixedLen;
            SprmResult aRet(pRet, x - nFixedLen);
            if (aRet.nRemainingData >= 1 && *aRet.pSprm == n2nd)
            {
                return aRet;
            }
        }
        // increment pointer so that it points to next SPRM
        i += x;
        pSp += x;
        WW8SprmIter aIter(pSprms.get(), nSprmSiz, maSprmParser);
        aRet = aIter.FindSprm(nId, &n2nd);
    }

    return SprmResult();   // Sprm not found
    return aRet;
}

WW8PLCFx_SubDoc::WW8PLCFx_SubDoc(SvStream* pSt, const WW8Fib& rFib,
diff --git a/sw/source/filter/ww8/ww8scan.hxx b/sw/source/filter/ww8/ww8scan.hxx
index dddc26a..fefb240 100644
--- a/sw/source/filter/ww8/ww8scan.hxx
+++ b/sw/source/filter/ww8/ww8scan.hxx
@@ -282,7 +282,7 @@ public:
    explicit WW8SprmIter(const sal_uInt8* pSprms_, sal_Int32 nLen_,
        const wwSprmParser &rSprmParser);
    void  SetSprms(const sal_uInt8* pSprms_, sal_Int32 nLen_);
    SprmResult FindSprm(sal_uInt16 nId);
    SprmResult FindSprm(sal_uInt16 nId, sal_uInt8* pNextByteMatch = nullptr);
    void  advance();
    const sal_uInt8* GetSprms() const
        { return ( pSprms && (0 < nRemLen) ) ? pSprms : nullptr; }