[Libreoffice-commits] core.git: include/sax include/xmloff offapi/com sax/source starmath/source xmloff/source
dante (via logerrit)
logerrit at kemper.freedesktop.org
Sat Dec 26 07:22:44 UTC 2020
include/sax/fastparser.hxx | 3 +--
include/xmloff/xmlimp.hxx | 3 +--
offapi/com/sun/star/xml/sax/XFastParser.idl | 4 +++-
sax/source/fastparser/fastparser.cxx | 23 +++++++++++------------
starmath/source/mathmlimport.cxx | 6 ++----
starmath/source/xparsmlbase.cxx | 14 ++++++++++----
starmath/source/xparsmlbase.hxx | 11 +++++------
xmloff/source/core/xmlimp.cxx | 5 ++---
8 files changed, 35 insertions(+), 34 deletions(-)
New commits:
commit 9f6dfd50cb03b6511d4f711d284e1b75783d0b8b
Author: dante <dante19031999 at gmail.com>
AuthorDate: Sat Dec 19 18:39:54 2020 +0100
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sat Dec 26 08:21:58 2020 +0100
Improve handle of custom XML entities
Since 7.1 hasn't been released yet there's still time to change it before having to be scared about backguards compatibility.
This way:
- It is more efficient than passing two arguments
- On definition it is simpler since both are declarated on same point.
So it is simpler to not loose sync between lists.
- Code is less long.
- Thanks to an idea proposed by Stephan Bergmann on other commit.
Change-Id: I16305a304c98eb8d4e11507c7938002da546778b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108028
Tested-by: Noel Grandin <noel.grandin at collabora.co.uk>
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/include/sax/fastparser.hxx b/include/sax/fastparser.hxx
index 5af3ac1d1f57..aebaa4056aa0 100644
--- a/include/sax/fastparser.hxx
+++ b/include/sax/fastparser.hxx
@@ -64,8 +64,7 @@ public:
virtual void SAL_CALL setEntityResolver( const css::uno::Reference< css::xml::sax::XEntityResolver >& Resolver ) override;
virtual void SAL_CALL setLocale( const css::lang::Locale& rLocale ) override;
virtual void SAL_CALL setNamespaceHandler( const css::uno::Reference< css::xml::sax::XFastNamespaceHandler >& Handler) override;
- virtual void SAL_CALL setCustomEntityNames( const ::css::uno::Sequence< ::rtl::OUString >& names,
- const ::css::uno::Sequence< ::rtl::OUString >& replacements ) override;
+ virtual void SAL_CALL setCustomEntityNames( const ::css::uno::Sequence< ::css::beans::Pair<::rtl::OUString, ::rtl::OUString> >& replacements ) override;
// XServiceInfo
virtual OUString SAL_CALL getImplementationName( ) override;
diff --git a/include/xmloff/xmlimp.hxx b/include/xmloff/xmlimp.hxx
index 9c402f199ffa..494de3cbcd26 100644
--- a/include/xmloff/xmlimp.hxx
+++ b/include/xmloff/xmlimp.hxx
@@ -335,8 +335,7 @@ public:
virtual void SAL_CALL setEntityResolver( const css::uno::Reference< css::xml::sax::XEntityResolver >& Resolver ) override;
virtual void SAL_CALL setLocale( const css::lang::Locale& rLocale ) override;
virtual void SAL_CALL setNamespaceHandler( const css::uno::Reference< css::xml::sax::XFastNamespaceHandler >& Handler) override;
- virtual void SAL_CALL setCustomEntityNames( const ::css::uno::Sequence< ::rtl::OUString >& names,
- const ::css::uno::Sequence< ::rtl::OUString >& replacements ) override;
+ virtual void SAL_CALL setCustomEntityNames( const ::css::uno::Sequence< ::css::beans::Pair<::rtl::OUString, ::rtl::OUString> >& replacements ) override;
// XImporter
virtual void SAL_CALL setTargetDocument( const css::uno::Reference< css::lang::XComponent >& xDoc ) override;
diff --git a/offapi/com/sun/star/xml/sax/XFastParser.idl b/offapi/com/sun/star/xml/sax/XFastParser.idl
index 9beefe4aa4d6..9d4439144b27 100644
--- a/offapi/com/sun/star/xml/sax/XFastParser.idl
+++ b/offapi/com/sun/star/xml/sax/XFastParser.idl
@@ -41,6 +41,8 @@
#include <com/sum/star/xml/sax/XFastNamespaceHandler.idl>
+#include <com/sun/star/beans/Pair.idl>
+
module com { module sun { module star { module xml { module sax {
@@ -163,7 +165,7 @@ interface XFastParser: com::sun::star::uno::XInterface
* Will allow to use customized entity references like ∞ .
* @since LibreOffice 7.1
*/
- void setCustomEntityNames( [in] sequence<string> names, [in] sequence<string> replacements);
+ void setCustomEntityNames( [in] sequence< beans::Pair<string,string> > replacements);
};
diff --git a/sax/source/fastparser/fastparser.cxx b/sax/source/fastparser/fastparser.cxx
index 85726599b41c..9d13d25ce385 100644
--- a/sax/source/fastparser/fastparser.cxx
+++ b/sax/source/fastparser/fastparser.cxx
@@ -250,7 +250,8 @@ public:
/// @throws css::uno::RuntimeException
void setNamespaceHandler( const css::uno::Reference< css::xml::sax::XFastNamespaceHandler >& Handler);
// Fake DTD file
- void setCustomEntityNames( const ::css::uno::Sequence< ::rtl::OUString >& names, const ::css::uno::Sequence< ::rtl::OUString >& replacements );
+ void setCustomEntityNames(
+ const ::css::uno::Sequence<::css::beans::Pair<::rtl::OUString, ::rtl::OUString>>& replacements);
// called by the C callbacks of the expat parser
void callbackStartElement( const xmlChar *localName , const xmlChar* prefix, const xmlChar* URI,
@@ -952,16 +953,15 @@ void FastSaxParserImpl::setNamespaceHandler( const Reference< XFastNamespaceHand
}
void FastSaxParserImpl::setCustomEntityNames(
- const ::css::uno::Sequence<::rtl::OUString>& names,
- const ::css::uno::Sequence<::rtl::OUString>& replacements)
+ const ::css::uno::Sequence<::css::beans::Pair<::rtl::OUString, ::rtl::OUString>>& replacements)
{
- m_Replacements.resize(names.size());
- for (size_t i = 0; i < names.size(); ++i)
+ m_Replacements.resize(replacements.size());
+ for (size_t i = 0; i < replacements.size(); ++i)
{
- m_Replacements[i].name = names[i];
- m_Replacements[i].replacement = replacements[i];
+ m_Replacements[i].name = replacements[i].First;
+ m_Replacements[i].replacement = replacements[i].Second;
}
- if (names.size() > 1)
+ if (m_Replacements.size() > 1)
std::sort(m_Replacements.begin(), m_Replacements.end());
}
@@ -1521,11 +1521,10 @@ OUString FastSaxParser::getImplementationName()
return "com.sun.star.comp.extensions.xml.sax.FastParser";
}
-void FastSaxParser::setCustomEntityNames(const ::css::uno::Sequence<::rtl::OUString>& names,
- const ::css::uno::Sequence<::rtl::OUString>& replacements)
+void FastSaxParser::setCustomEntityNames(
+ const ::css::uno::Sequence<::css::beans::Pair<::rtl::OUString, ::rtl::OUString>>& replacements)
{
- assert(names.size() == replacements.size());
- mpImpl->setCustomEntityNames(names, replacements);
+ mpImpl->setCustomEntityNames(replacements);
}
sal_Bool FastSaxParser::supportsService( const OUString& ServiceName )
diff --git a/starmath/source/mathmlimport.cxx b/starmath/source/mathmlimport.cxx
index 04c4bc6b8837..fd27d226a948 100644
--- a/starmath/source/mathmlimport.cxx
+++ b/starmath/source/mathmlimport.cxx
@@ -270,16 +270,14 @@ ErrCode SmXMLImportWrapper::ReadThroughComponent(const Reference<io::XInputStrea
Reference<css::xml::sax::XFastDocumentHandler> xFastDocHandler(xFilter, UNO_QUERY);
if (xFastParser)
{
- xFastParser->setCustomEntityNames(starmathdatabase::icustomMathmlHtmlEntitiesNames,
- starmathdatabase::icustomMathmlHtmlEntitiesValues);
+ xFastParser->setCustomEntityNames(starmathdatabase::icustomMathmlHtmlEntities);
xFastParser->parseStream(aParserInput);
}
else if (xFastDocHandler)
{
Reference<css::xml::sax::XFastParser> xParser
= css::xml::sax::FastParser::create(rxContext);
- xParser->setCustomEntityNames(starmathdatabase::icustomMathmlHtmlEntitiesNames,
- starmathdatabase::icustomMathmlHtmlEntitiesValues);
+ xParser->setCustomEntityNames(starmathdatabase::icustomMathmlHtmlEntities);
xParser->setFastDocumentHandler(xFastDocHandler);
xParser->parseStream(aParserInput);
}
diff --git a/starmath/source/xparsmlbase.cxx b/starmath/source/xparsmlbase.cxx
index b8bb6c7fc329..b699e7935fbe 100644
--- a/starmath/source/xparsmlbase.cxx
+++ b/starmath/source/xparsmlbase.cxx
@@ -18,6 +18,7 @@
*/
#include "xparsmlbase.hxx"
+/*
static OUString icustomMathmlHtmlEntitiesNamesData[2125] = {
// clang-format off
u"AElig",
@@ -4277,11 +4278,16 @@ static OUString icustomMathmlHtmlEntitiesValuesData[2125] = {
u"\u200C"
// clang-format on
};
+*/
-const ::css::uno::Sequence<::rtl::OUString>
- starmathdatabase::icustomMathmlHtmlEntitiesNames(icustomMathmlHtmlEntitiesNamesData, 2125);
+static ::css::beans::Pair<::rtl::OUString, ::rtl::OUString> icustomMathmlHtmlEntitiesData[2] = {
+ // clang-format off
+ { u"infin", u"\u221E" },
+ { u"sigma", u"\u03C3" }
+ // clang-format on
+};
-const ::css::uno::Sequence<::rtl::OUString>
- starmathdatabase::icustomMathmlHtmlEntitiesValues(icustomMathmlHtmlEntitiesValuesData, 2125);
+const ::css::uno::Sequence<::css::beans::Pair<OUString, OUString>>
+ starmathdatabase::icustomMathmlHtmlEntities(icustomMathmlHtmlEntitiesData, 2);
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/starmath/source/xparsmlbase.hxx b/starmath/source/xparsmlbase.hxx
index f9b58de7ca89..6603d23293db 100644
--- a/starmath/source/xparsmlbase.hxx
+++ b/starmath/source/xparsmlbase.hxx
@@ -21,6 +21,7 @@
#define XPARSEMLBASE
#include <com/sun/star/uno/Sequence.hxx>
+#include <com/sun/star/beans/Pair.hpp>
namespace starmathdatabase
{
/**
@@ -32,16 +33,14 @@ namespace starmathdatabase
* On export only mathml entities are allowed.
* Some documentation: https://www.w3.org/TR/MathML3/chapter7.html
*/
+
/**
* Entity names for mathml. Example: ∞
+ * These ones are to be used on import.
* Must be in sync with customMathmlHtmlEntitiesNames.
*/
-const extern ::css::uno::Sequence<::rtl::OUString> icustomMathmlHtmlEntitiesNames;
-/**
- * Entity values for mathml. Example: ∞ -> "\u8734";
- * Must be in sync with customMathmlHtmlEntitiesNames.
- */
-const extern ::css::uno::Sequence<::rtl::OUString> icustomMathmlHtmlEntitiesValues;
+const extern ::css::uno::Sequence<::css::beans::Pair<::rtl::OUString, ::rtl::OUString>>
+ icustomMathmlHtmlEntities;
};
#endif /*XPARSEMLBASE*/
diff --git a/xmloff/source/core/xmlimp.cxx b/xmloff/source/core/xmlimp.cxx
index 5f1e7ec1b20a..9d3b1115f57e 100644
--- a/xmloff/source/core/xmlimp.cxx
+++ b/xmloff/source/core/xmlimp.cxx
@@ -544,10 +544,9 @@ void SAL_CALL SvXMLImport::setNamespaceHandler( const uno::Reference< xml::sax::
mxParser->setNamespaceHandler( Handler );
}
-void SAL_CALL SvXMLImport::setCustomEntityNames( const ::css::uno::Sequence< ::rtl::OUString >& names,
- const ::css::uno::Sequence< ::rtl::OUString >& replacements )
+void SAL_CALL SvXMLImport::setCustomEntityNames( const ::css::uno::Sequence< ::css::beans::Pair<::rtl::OUString, ::rtl::OUString> >& replacements )
{
- mxParser->setCustomEntityNames( names, replacements );
+ mxParser->setCustomEntityNames( replacements );
}
void SAL_CALL SvXMLImport::startDocument()
More information about the Libreoffice-commits
mailing list