From d66a2686d0f1abdffb129105881302ab94ab42ee Mon Sep 17 00:00:00 2001 From: Michael Meeks Date: Sat, 12 Jul 2025 12:03:15 +0100 Subject: [PATCH] Add content mapping into XFastParser. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ideally this gets done for free in the parsing thread. Change-Id: I2392fd51c8152c48cf03ac9ed26e6f62aa6ac4f8 Signed-off-by: Michael Meeks Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193626 Tested-by: Jenkins CollaboraOffice Reviewed-by: Andras Timar Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195191 Tested-by: Jenkins Reviewed-by: Caolán McNamara --- sax/source/fastparser/fastparser.cxx | 29 ++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/sax/source/fastparser/fastparser.cxx b/sax/source/fastparser/fastparser.cxx index 744458972554..32dc46506617 100644 --- a/sax/source/fastparser/fastparser.cxx +++ b/sax/source/fastparser/fastparser.cxx @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -37,6 +38,7 @@ #include #include #include +#include #include #include @@ -271,6 +273,7 @@ public: void produce( bool bForceFlush = false ); bool m_bIgnoreMissingNSDecl; bool m_bDisableThreadedParser; + css::uno::Reference mxMap; /// _ prefix string mapper for translation private: bool consume(EventList&); @@ -1360,6 +1363,10 @@ void FastSaxParserImpl::sendPendingCharacters() { Entity& rEntity = getEntity(); OUString sChars( pendingCharacters.data(), pendingCharacters.size(), RTL_TEXTENCODING_UTF8 ); + + if (sChars[0] == '_' && mxMap) + mxMap->get(uno::Any(sChars)) >>= sChars; + if (rEntity.mbEnableThreads) { Event& rEvent = rEntity.getEvent( CallbackType::CHARACTERS ); @@ -1463,15 +1470,21 @@ FastSaxParser::initialize(css::uno::Sequence< css::uno::Any > const& rArguments) if ( !(rArguments[0] >>= str) ) throw IllegalArgumentException(); - if ( str == "IgnoreMissingNSDecl" ) - mpImpl->m_bIgnoreMissingNSDecl = true; - else if ( str == "DoSmeplease" ) - ; //just ignore as this is already immune to billion laughs - else if ( str == "DisableThreadedParser" ) - mpImpl->m_bDisableThreadedParser = true; - else - throw IllegalArgumentException(); + auto opts = comphelper::string::split(str, ','); + for (auto &s : opts) + { + if ( s == "IgnoreMissingNSDecl" ) + mpImpl->m_bIgnoreMissingNSDecl = true; + else if ( s == "DoSmeplease" ) + ; //just ignore as this is already immune to billion laughs + else if ( s == "DisableThreadedParser" ) + mpImpl->m_bDisableThreadedParser = true; + else + throw IllegalArgumentException(); + } + if (rArguments.size() > 1) + rArguments[1] >>= mpImpl->mxMap; } void FastSaxParser::parseStream( const xml::sax::InputSource& aInputSource )