summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSzymon Kłos <szymon.klos@collabora.com>2023-04-07 09:48:41 +0200
committerSzymon Kłos <szymon.klos@collabora.com>2023-04-07 19:33:46 +0200
commitcb00ec7cbfc7900c3a31e7fdc4916668a1fa4c11 (patch)
treec4bc2a1c9a7f7b2422aaa0580408fd963ce42541
parentBump version to 21.06.37.1 (diff)
downloadcore-cb00ec7cbfc7900c3a31e7fdc4916668a1fa4c11.tar.gz
core-cb00ec7cbfc7900c3a31e7fdc4916668a1fa4c11.zip
Make encodeForXml accessible for other modules
and share similar code Change-Id: I7729a46d40845893f577c273c1ab340f69ebb51b
-rw-r--r--desktop/source/deployment/registry/configuration/dp_configuration.cxx36
-rw-r--r--include/rtl/xmlencode.hxx55
-rw-r--r--sd/source/filter/html/htmlex.cxx5
-rw-r--r--sw/source/filter/html/css1atr.cxx3
-rw-r--r--sw/source/filter/html/htmlfldw.cxx3
-rw-r--r--vcl/source/gdi/pdfwriter_impl.cxx39
6 files changed, 68 insertions, 73 deletions
diff --git a/desktop/source/deployment/registry/configuration/dp_configuration.cxx b/desktop/source/deployment/registry/configuration/dp_configuration.cxx
index 578e164f13b7..ae9aaae51138 100644
--- a/desktop/source/deployment/registry/configuration/dp_configuration.cxx
+++ b/desktop/source/deployment/registry/configuration/dp_configuration.cxx
@@ -30,6 +30,7 @@
#include <rtl/string.hxx>
#include <rtl/strbuf.hxx>
#include <rtl/ustrbuf.hxx>
+#include <rtl/xmlencode.hxx>
#include <cppuhelper/exc_hlp.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <ucbhelper/content.hxx>
@@ -566,39 +567,6 @@ BackendImpl::PackageImpl::isRegistered_(
}
-OUString encodeForXml( OUString const & text )
-{
- // encode conforming xml:
- sal_Int32 len = text.getLength();
- OUStringBuffer buf;
- for ( sal_Int32 pos = 0; pos < len; ++pos )
- {
- sal_Unicode c = text[ pos ];
- switch (c) {
- case '<':
- buf.append( "&lt;" );
- break;
- case '>':
- buf.append( "&gt;" );
- break;
- case '&':
- buf.append( "&amp;" );
- break;
- case '\'':
- buf.append( "&apos;" );
- break;
- case '\"':
- buf.append( "&quot;" );
- break;
- default:
- buf.append( c );
- break;
- }
- }
- return buf.makeStringAndClear();
-}
-
-
OUString replaceOrigin(
OUString const & url, OUString const & destFolder, Reference< XCommandEnvironment > const & xCmdEnv, Reference< XComponentContext > const & xContext, bool & out_replaced)
{
@@ -651,7 +619,7 @@ OUString replaceOrigin(
if (origin.isEmpty()) {
// encode only once
origin = OUStringToOString(
- encodeForXml( url.copy( 0, url.lastIndexOf( '/' ) ) ),
+ rtl::encodeForXml( url.subView( 0, url.lastIndexOf( '/' ) ) ),
// xxx todo: encode always for UTF-8? => lookup doc-header?
RTL_TEXTENCODING_UTF8 );
}
diff --git a/include/rtl/xmlencode.hxx b/include/rtl/xmlencode.hxx
new file mode 100644
index 000000000000..487c4ee94749
--- /dev/null
+++ b/include/rtl/xmlencode.hxx
@@ -0,0 +1,55 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_RTL_XMLENCODE_HXX
+#define INCLUDED_RTL_XMLENCODE_HXX
+
+#include "rtl/ustring.hxx"
+
+namespace rtl
+{
+inline OUString encodeForXml(std::u16string_view rStr)
+{
+ // encode conforming xml:
+ sal_Int32 len = rStr.length();
+ OUStringBuffer buf;
+ for (sal_Int32 pos = 0; pos < len; ++pos)
+ {
+ sal_Unicode c = rStr[pos];
+ switch (c)
+ {
+ case '<':
+ buf.append("&lt;");
+ break;
+ case '>':
+ buf.append("&gt;");
+ break;
+ case '&':
+ buf.append("&amp;");
+ break;
+ case '\'':
+ buf.append("&apos;");
+ break;
+ case '\"':
+ buf.append("&quot;");
+ break;
+ default:
+ buf.append(c);
+ break;
+ }
+ }
+
+ return buf.makeStringAndClear();
+}
+
+} /* Namespace */
+
+#endif // INCLUDED_RTL_XMLENCODE_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ \ No newline at end of file
diff --git a/sd/source/filter/html/htmlex.cxx b/sd/source/filter/html/htmlex.cxx
index 7b1efa7e14b5..5cc1a3ca32f5 100644
--- a/sd/source/filter/html/htmlex.cxx
+++ b/sd/source/filter/html/htmlex.cxx
@@ -23,6 +23,7 @@
#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/ucb/SimpleFileAccess.hpp>
+#include <rtl/xmlencode.hxx>
#include <sal/log.hxx>
#include <rtl/tencinfo.h>
#include <comphelper/processfactory.hxx>
@@ -287,10 +288,10 @@ OUString HtmlState::SetLink( const OUString& aLink, const OUString& aTarget )
if (!aLink.isEmpty())
{
- aStr += "<a href=\"" + aLink;
+ aStr += "<a href=\"" + rtl::encodeForXml(aLink);
if (!aTarget.isEmpty())
{
- aStr += "\" target=\"" + aTarget;
+ aStr += "\" target=\"" + rtl::encodeForXml(aTarget);
}
aStr += "\">";
mbLink = true;
diff --git a/sw/source/filter/html/css1atr.cxx b/sw/source/filter/html/css1atr.cxx
index c401d95a788f..cbf98227a02d 100644
--- a/sw/source/filter/html/css1atr.cxx
+++ b/sw/source/filter/html/css1atr.cxx
@@ -93,6 +93,7 @@
#include <o3tl/typed_flags_set.hxx>
#include <rtl/strbuf.hxx>
+#include <rtl/xmlencode.hxx>
using namespace css;
using editeng::SvxBorderLine;
@@ -1114,7 +1115,7 @@ void SwHTMLWriter::PrepareFontList( const SvxFontItem& rFontItem,
while( nStrPos != -1 )
{
OUString aName = rName.getToken( 0, ';', nStrPos );
- aName = comphelper::string::strip(aName, ' ');
+ aName = rtl::encodeForXml(comphelper::string::strip(aName, ' '));
if( aName.isEmpty() )
continue;
diff --git a/sw/source/filter/html/htmlfldw.cxx b/sw/source/filter/html/htmlfldw.cxx
index 825d563a9f39..391331d6538d 100644
--- a/sw/source/filter/html/htmlfldw.cxx
+++ b/sw/source/filter/html/htmlfldw.cxx
@@ -21,6 +21,7 @@
#include <comphelper/string.hxx>
#include <svtools/htmlkywd.hxx>
#include <svtools/htmlout.hxx>
+#include <rtl/xmlencode.hxx>
#include <osl/diagnose.h>
#include <fmtfld.hxx>
#include <doc.hxx>
@@ -512,7 +513,7 @@ Writer& OutHTML_SwFormatField( Writer& rWrt, const SfxPoolItem& rHt )
OString sOut =
"<" OOO_STRING_SVTOOLS_HTML_comment
" " +
- OUStringToOString(sComment, static_cast<SwHTMLWriter&>(rWrt).m_eDestEnc) +
+ OUStringToOString(rtl::encodeForXml(sComment), static_cast<SwHTMLWriter&>(rWrt).m_eDestEnc) +
" -->";
rWrt.Strm().WriteOString( sOut );
}
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index 3e934a19825d..7b1927a65edf 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -47,6 +47,7 @@
#include <osl/thread.h>
#include <rtl/digest.h>
#include <rtl/ustrbuf.hxx>
+#include <rtl/xmlencode.hxx>
#include <sal/log.hxx>
#include <svl/urihelper.hxx>
#include <tools/fract.hxx>
@@ -5192,43 +5193,11 @@ sal_Int32 PDFWriterImpl::emitOutputIntent()
return nOIObject;
}
-// formats the string for the XML stream
-static void escapeStringXML( const OUString& rStr, OUString &rValue)
+static void lcl_assignMeta(std::u16string_view aValue, OString& aMeta)
{
- const sal_Unicode* pUni = rStr.getStr();
- int nLen = rStr.getLength();
- for( ; nLen; nLen--, pUni++ )
+ if (!aValue.empty())
{
- switch( *pUni )
- {
- case u'&':
- rValue += "&amp;";
- break;
- case u'<':
- rValue += "&lt;";
- break;
- case u'>':
- rValue += "&gt;";
- break;
- case u'\'':
- rValue += "&apos;";
- break;
- case u'"':
- rValue += "&quot;";
- break;
- default:
- rValue += OUStringChar( *pUni );
- break;
- }
- }
-}
-
-static void lcl_assignMeta(const OUString& aValue, OString& aMeta)
-{
- if (!aValue.isEmpty())
- {
- OUString aTempString;
- escapeStringXML(aValue, aTempString);
+ OUString aTempString = rtl::encodeForXml(aValue);
aMeta = OUStringToOString(aTempString, RTL_TEXTENCODING_UTF8);
}
}