drawinglayer/source/tools/primitive2dxmldump.cxx | 10 ++---- include/tools/XmlWriter.hxx | 14 +++++---- tools/source/xml/XmlWriter.cxx | 33 ++++++++++++++++------- 3 files changed, 35 insertions(+), 22 deletions(-)
New commits: commit 81f4f1ea1d13dcdf8ea693a48ce2d753729d87aa Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Sat Jul 22 16:23:15 2023 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Sat Jul 22 23:01:02 2023 +0200 simplify some calls to XmlWriter::attribute Change-Id: Ibc3aa732dec2f6c26750ba056f5f8d71ae34b63e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154765 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/drawinglayer/source/tools/primitive2dxmldump.cxx b/drawinglayer/source/tools/primitive2dxmldump.cxx index 38e6a3ea9773..0585ce7168f8 100644 --- a/drawinglayer/source/tools/primitive2dxmldump.cxx +++ b/drawinglayer/source/tools/primitive2dxmldump.cxx @@ -616,8 +616,7 @@ public: default: { rWriter.startElement("unhandled"); - rWriter.attribute("id", - OUStringToOString(sCurrentElementTag, RTL_TEXTENCODING_UTF8)); + rWriter.attribute("id", sCurrentElementTag); rWriter.attribute("idNumber", nId); drawinglayer::geometry::ViewInformation3D aViewInformation3D; @@ -1217,8 +1216,7 @@ void Primitive2dXmlDump::decomposeAndWrite( } } rWriter.startElement(aName); - rWriter.attribute("id", - OUStringToOString(sCurrentElementTag, RTL_TEXTENCODING_UTF8)); + rWriter.attribute("id", sCurrentElementTag); rWriter.attribute("idNumber", nId); auto pBufferedDecomposition commit 2006d7455f529d3d6f44d09a83be9a80e73b1d34 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Sat Jul 22 16:20:16 2023 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Sat Jul 22 23:00:53 2023 +0200 no need to create OString temporaries when calling XmlWriter methods Change-Id: Ief1101c55a0635dac43a7c4d66dd4ed0d5be70bd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154764 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/drawinglayer/source/tools/primitive2dxmldump.cxx b/drawinglayer/source/tools/primitive2dxmldump.cxx index a68692649f46..38e6a3ea9773 100644 --- a/drawinglayer/source/tools/primitive2dxmldump.cxx +++ b/drawinglayer/source/tools/primitive2dxmldump.cxx @@ -925,7 +925,7 @@ void Primitive2dXmlDump::decomposeAndWrite( for (size_t iDx = 0; iDx < aDx.size(); ++iDx) { OString sName = "dx" + OString::number(iDx); - rWriter.attribute(sName, OUString::number(aDx[iDx])); + rWriter.attribute(sName, OString::number(aDx[iDx])); } } rWriter.endElement(); @@ -1207,7 +1207,7 @@ void Primitive2dXmlDump::decomposeAndWrite( default: { - OString aName("unhandled"); + const char* aName = "unhandled"; switch (nId) { case PRIMITIVE2D_ID_RANGE_SVX | 14: // PRIMITIVE2D_ID_SDRCELLPRIMITIVE2D diff --git a/include/tools/XmlWriter.hxx b/include/tools/XmlWriter.hxx index e8f6579b0e95..400748611bd5 100644 --- a/include/tools/XmlWriter.hxx +++ b/include/tools/XmlWriter.hxx @@ -44,21 +44,23 @@ public: bool startDocument(sal_Int32 nIndent = 2, bool bWriteXmlHeader = true); void endDocument(); + void startElement(const char* sName); void startElement(const OString& sName); void startElement(const OString& sPrefix, const OString& sName, const OString& sNamespaceUri); void endElement(); + void attribute(const char* sTagName, const OString& aValue); void attribute(const OString& sTagName, const OString& aValue); - void attribute(const OString& sTagName, std::u16string_view aValue); - void attribute(const OString& sTagName, sal_Int32 aNumber); - void attributeDouble(const OString& sTagName, double aNumber); - void attributeBase64(const OString& sTagName, std::vector<sal_uInt8> const& rValueInBytes); - void attributeBase64(const OString& sTagName, std::vector<char> const& rValueInBytes); + void attribute(const char* sTagName, std::u16string_view aValue); + void attribute(const char* sTagName, sal_Int32 aNumber); + void attributeDouble(const char* sTagName, double aNumber); + void attributeBase64(const char* sTagName, std::vector<sal_uInt8> const& rValueInBytes); + void attributeBase64(const char* sTagName, std::vector<char> const& rValueInBytes); void content(const OString& sValue); void content(std::u16string_view sValue); - void element(const OString& sName); + void element(const char* sName); }; } // end tools namespace diff --git a/tools/source/xml/XmlWriter.cxx b/tools/source/xml/XmlWriter.cxx index a13190ecf9d2..424b13c67b01 100644 --- a/tools/source/xml/XmlWriter.cxx +++ b/tools/source/xml/XmlWriter.cxx @@ -93,28 +93,41 @@ void XmlWriter::startElement(const OString& sPrefix, const OString& sName, (void)xmlTextWriterStartElementNS(mpImpl->mpWriter, xmlPrefix, xmlName, xmlNamespaceUri); } -void XmlWriter::startElement(const OString& sName) +void XmlWriter::startElement(const char* pName) { - xmlChar* xmlName = BAD_CAST(sName.getStr()); + xmlChar* xmlName = BAD_CAST(pName); + (void)xmlTextWriterStartElement(mpImpl->mpWriter, xmlName); +} + +void XmlWriter::startElement(const OString& rName) +{ + xmlChar* xmlName = BAD_CAST(rName.getStr()); (void)xmlTextWriterStartElement(mpImpl->mpWriter, xmlName); } void XmlWriter::endElement() { (void)xmlTextWriterEndElement(mpImpl->mpWriter); } -void XmlWriter::attributeBase64(const OString& rsName, std::vector<sal_uInt8> const& rValueInBytes) +void XmlWriter::attributeBase64(const char* pName, std::vector<sal_uInt8> const& rValueInBytes) { std::vector<char> aSignedBytes(rValueInBytes.begin(), rValueInBytes.end()); - attributeBase64(rsName, aSignedBytes); + attributeBase64(pName, aSignedBytes); } -void XmlWriter::attributeBase64(const OString& rsName, std::vector<char> const& rValueInBytes) +void XmlWriter::attributeBase64(const char* pName, std::vector<char> const& rValueInBytes) { - xmlChar* xmlName = BAD_CAST(rsName.getStr()); + xmlChar* xmlName = BAD_CAST(pName); (void)xmlTextWriterStartAttribute(mpImpl->mpWriter, xmlName); (void)xmlTextWriterWriteBase64(mpImpl->mpWriter, rValueInBytes.data(), 0, rValueInBytes.size()); (void)xmlTextWriterEndAttribute(mpImpl->mpWriter); } +void XmlWriter::attribute(const char* name, const OString& value) +{ + xmlChar* xmlName = BAD_CAST(name); + xmlChar* xmlValue = BAD_CAST(value.getStr()); + (void)xmlTextWriterWriteAttribute(mpImpl->mpWriter, xmlName, xmlValue); +} + void XmlWriter::attribute(const OString& name, const OString& value) { xmlChar* xmlName = BAD_CAST(name.getStr()); @@ -122,17 +135,17 @@ void XmlWriter::attribute(const OString& name, const OString& value) (void)xmlTextWriterWriteAttribute(mpImpl->mpWriter, xmlName, xmlValue); } -void XmlWriter::attribute(const OString& name, std::u16string_view value) +void XmlWriter::attribute(const char* name, std::u16string_view value) { attribute(name, OUStringToOString(value, RTL_TEXTENCODING_UTF8)); } -void XmlWriter::attribute(const OString& name, const sal_Int32 aNumber) +void XmlWriter::attribute(const char* name, const sal_Int32 aNumber) { attribute(name, OString::number(aNumber)); } -void XmlWriter::attributeDouble(const OString& name, const double aNumber) +void XmlWriter::attributeDouble(const char* name, const double aNumber) { attribute(name, OString::number(aNumber)); } @@ -148,7 +161,7 @@ void XmlWriter::content(std::u16string_view sValue) content(OUStringToOString(sValue, RTL_TEXTENCODING_UTF8)); } -void XmlWriter::element(const OString& sName) +void XmlWriter::element(const char* sName) { startElement(sName); endElement();