diff options
-rw-r--r-- | include/svtools/HtmlWriter.hxx | 13 | ||||
-rw-r--r-- | svtools/qa/unit/testHtmlWriter.cxx | 2 | ||||
-rw-r--r-- | svtools/source/svhtml/HtmlWriter.cxx | 53 | ||||
-rw-r--r-- | sw/source/filter/html/htmlatr.cxx | 14 | ||||
-rw-r--r-- | sw/source/filter/html/htmlflywriter.cxx | 10 | ||||
-rw-r--r-- | sw/source/filter/html/wrthtml.hxx | 4 |
6 files changed, 35 insertions, 61 deletions
diff --git a/include/svtools/HtmlWriter.hxx b/include/svtools/HtmlWriter.hxx index 9fe66a7d9ad2..a53b41d0522e 100644 --- a/include/svtools/HtmlWriter.hxx +++ b/include/svtools/HtmlWriter.hxx @@ -11,6 +11,7 @@ #pragma once #include <rtl/string.hxx> +#include <rtl/ustring.hxx> #include <string_view> #include <vector> #include <svtools/svtdllapi.h> @@ -42,19 +43,17 @@ public: void flushStack(); - static void writeAttribute(SvStream& rStream, std::string_view aAttribute, sal_Int32 aValue); - static void writeAttribute(SvStream& rStream, std::string_view aAttribute, - std::string_view aValue); - - void attribute(std::string_view aAttribute, const char* aValue); void attribute(std::string_view aAttribute, sal_Int32 aValue); void attribute(std::string_view aAttribute, std::string_view aValue); - void attribute(std::string_view aAttribute, std::u16string_view aValue); + void attribute(std::string_view aAttribute, const OUString& aValue); + template <size_t N> void attribute(std::string_view aAttribute, const char (&aValue)[N]) + { + attribute(aAttribute, OUString(aValue)); + } // boolean attribute e.g. <img ismap> void attribute(std::string_view aAttribute); void single(const OString& aContent); - void endAttribute(); /// Writes character data. void characters(std::string_view rChars); diff --git a/svtools/qa/unit/testHtmlWriter.cxx b/svtools/qa/unit/testHtmlWriter.cxx index 3e7e10d34c12..513978b1f525 100644 --- a/svtools/qa/unit/testHtmlWriter.cxx +++ b/svtools/qa/unit/testHtmlWriter.cxx @@ -157,7 +157,7 @@ CPPUNIT_TEST_FIXTURE(Test, testAttributeValues) aHtml.prettyPrint(false); aHtml.start("abc"_ostr); aHtml.attribute("one", "one"); - aHtml.attribute("two", u"two"); + aHtml.attribute("two", u"two"_ustr); aHtml.attribute("three", sal_Int32(12)); aHtml.end(); diff --git a/svtools/source/svhtml/HtmlWriter.cxx b/svtools/source/svhtml/HtmlWriter.cxx index 28a86bbce12a..cd73bad074da 100644 --- a/svtools/source/svhtml/HtmlWriter.cxx +++ b/svtools/source/svhtml/HtmlWriter.cxx @@ -25,7 +25,9 @@ HtmlWriter::HtmlWriter(SvStream& rStream, std::string_view rNamespace) : } HtmlWriter::~HtmlWriter() -{} +{ + assert(maElementStack.empty()); +} void HtmlWriter::prettyPrint(bool b) { @@ -61,17 +63,6 @@ void HtmlWriter::single(const OString &aContent) end(); } -void HtmlWriter::endAttribute() -{ - if (mbOpeningTagOpen) - { - mrStream.WriteOString("/>"); - if (mbPrettyPrint) - mrStream.WriteOString("\n"); - mbOpeningTagOpen = false; - } -} - void HtmlWriter::flushStack() { while (!maElementStack.empty()) @@ -115,27 +106,9 @@ void HtmlWriter::end() maElementStack.pop_back(); } -void HtmlWriter::writeAttribute(SvStream& rStream, std::string_view aAttribute, sal_Int32 aValue) -{ - writeAttribute(rStream, aAttribute, OString::number(aValue)); -} - -void HtmlWriter::writeAttribute(SvStream& rStream, std::string_view aAttribute, std::string_view aValue) -{ - rStream.WriteOString(aAttribute); - rStream.WriteChar('='); - rStream.WriteChar('"'); - HTMLOutFuncs::Out_String(rStream, OStringToOUString(aValue, RTL_TEXTENCODING_UTF8)); - rStream.WriteChar('"'); -} - void HtmlWriter::attribute(std::string_view aAttribute, std::string_view aValue) { - if (mbOpeningTagOpen && !aAttribute.empty() && !aValue.empty()) - { - mrStream.WriteChar(' '); - writeAttribute(mrStream, aAttribute, aValue); - } + attribute(aAttribute, OStringToOUString(aValue, RTL_TEXTENCODING_UTF8)); } void HtmlWriter::attribute(std::string_view aAttribute, const sal_Int32 aValue) @@ -143,18 +116,22 @@ void HtmlWriter::attribute(std::string_view aAttribute, const sal_Int32 aValue) attribute(aAttribute, OString::number(aValue)); } -void HtmlWriter::attribute(std::string_view aAttribute, const char* pValue) +void HtmlWriter::attribute(std::string_view aAttribute, const OUString& aValue) { - attribute(aAttribute, std::string_view(pValue)); -} - -void HtmlWriter::attribute(std::string_view aAttribute, std::u16string_view aValue) -{ - attribute(aAttribute, OUStringToOString(aValue, RTL_TEXTENCODING_UTF8)); + assert(mbOpeningTagOpen); + if (mbOpeningTagOpen && !aAttribute.empty() && !aValue.isEmpty()) + { + mrStream.WriteChar(' '); + mrStream.WriteOString(aAttribute); + mrStream.WriteOString("=\""); + HTMLOutFuncs::Out_String(mrStream, aValue); + mrStream.WriteChar('"'); + } } void HtmlWriter::attribute(std::string_view aAttribute) { + assert(mbOpeningTagOpen); if (mbOpeningTagOpen && !aAttribute.empty()) { mrStream.WriteChar(' '); diff --git a/sw/source/filter/html/htmlatr.cxx b/sw/source/filter/html/htmlatr.cxx index 8a20167c8bc4..b4ed5c567cff 100644 --- a/sw/source/filter/html/htmlatr.cxx +++ b/sw/source/filter/html/htmlatr.cxx @@ -771,18 +771,16 @@ static void OutHTML_SwFormat( SwHTMLWriter& rWrt, const SwFormat& rFormat, } if( rInfo.bInNumberBulletList && bNumberedForListItem ) { - HtmlWriter html(rWrt.Strm(), rWrt.maNamespace); - html.prettyPrint(rWrt.IsPrettyPrint()); - html.start(OOO_STRING_SVTOOLS_HTML_li ""_ostr); + OStringBuffer sOut(rWrt.GetNamespace() + OOO_STRING_SVTOOLS_HTML_li); if (!bNumbered) { // Handles list headers (<text:list-header> ODF element) - html.attribute(OOO_STRING_SVTOOLS_HTML_O_style, "display: block"); + sOut.append(" " OOO_STRING_SVTOOLS_HTML_O_style "=\"display: block\""); } else if (USHRT_MAX != nNumStart) - html.attribute(OOO_STRING_SVTOOLS_HTML_O_value, OString::number(nNumStart)); - // Finish the opening element, but don't close it. - html.characters(""); + sOut.append(" " OOO_STRING_SVTOOLS_HTML_O_value "=\"" + OString::number(nNumStart) + + "\""); + HTMLOutFuncs::Out_AsciiTag(rWrt.Strm(), sOut); } if( rWrt.m_nDefListLvl > 0 && !bForceDL ) @@ -2117,7 +2115,7 @@ SwHTMLWriter& OutHTML_SwTextNode( SwHTMLWriter& rWrt, const SwContentNode& rNode const SfxItemSet* pItemSet = pNd->GetpSwAttrSet(); if( !pItemSet ) { - aHtml.endAttribute(); + aHtml.end(); return rWrt; } if (pItemSet->GetItemIfSet(RES_MARGIN_FIRSTLINE, false) diff --git a/sw/source/filter/html/htmlflywriter.cxx b/sw/source/filter/html/htmlflywriter.cxx index 3303cabee0f6..9976124b3adc 100644 --- a/sw/source/filter/html/htmlflywriter.cxx +++ b/sw/source/filter/html/htmlflywriter.cxx @@ -771,7 +771,7 @@ OString SwHTMLWriter::OutFrameFormatOptions( const SwFrameFormat &rFrameFormat, return sRetEndTags; } -void SwHTMLWriter::writeFrameFormatOptions(HtmlWriter& aHtml, const SwFrameFormat& rFrameFormat, std::u16string_view rAlternateText, HtmlFrmOpts nFrameOptions) +void SwHTMLWriter::writeFrameFormatOptions(HtmlWriter& aHtml, const SwFrameFormat& rFrameFormat, const OUString& rAlternateText, HtmlFrmOpts nFrameOptions) { bool bReplacement = (nFrameOptions & HtmlFrmOpts::Replacement) || mbReqIF; const SfxItemSet& rItemSet = rFrameFormat.GetAttrSet(); @@ -793,7 +793,7 @@ void SwHTMLWriter::writeFrameFormatOptions(HtmlWriter& aHtml, const SwFrameForma } // alt - if( (nFrameOptions & HtmlFrmOpts::Alt) && !rAlternateText.empty() && !bReplacement ) + if( (nFrameOptions & HtmlFrmOpts::Alt) && !rAlternateText.isEmpty() && !bReplacement ) { aHtml.attribute(OOO_STRING_SVTOOLS_HTML_O_alt, rAlternateText); } @@ -1228,7 +1228,7 @@ SwHTMLWriter& OutHTML_ImageStart( HtmlWriter& rHtml, SwHTMLWriter& rWrt, const S const Size &rRealSize, HtmlFrmOpts nFrameOpts, const char *pMarkType, const ImageMap *pAltImgMap, - std::u16string_view rMimeType ) + const OUString& rMimeType ) { // <object data="..."> instead of <img src="..."> bool bReplacement = (nFrameOpts & HtmlFrmOpts::Replacement) || rWrt.mbReqIF; @@ -1400,7 +1400,7 @@ SwHTMLWriter& OutHTML_ImageStart( HtmlWriter& rHtml, SwHTMLWriter& rWrt, const S if (bReplacement) { // Handle XHTML type attribute for OLE replacement images. - if (!rMimeType.empty()) + if (!rMimeType.isEmpty()) rHtml.attribute(OOO_STRING_SVTOOLS_HTML_O_type, rMimeType); } @@ -1431,7 +1431,7 @@ SwHTMLWriter& OutHTML_ImageStart( HtmlWriter& rHtml, SwHTMLWriter& rWrt, const S if( !aIMapName.isEmpty() ) { - rHtml.attribute(OOO_STRING_SVTOOLS_HTML_O_usemap, Concat2View("#" + aIMapName)); + rHtml.attribute(OOO_STRING_SVTOOLS_HTML_O_usemap, "#" + aIMapName); } if (bReplacement) diff --git a/sw/source/filter/html/wrthtml.hxx b/sw/source/filter/html/wrthtml.hxx index 07a8281be13d..a62bff941a1d 100644 --- a/sw/source/filter/html/wrthtml.hxx +++ b/sw/source/filter/html/wrthtml.hxx @@ -512,7 +512,7 @@ public: OString OutFrameFormatOptions( const SwFrameFormat& rFrameFormat, const OUString& rAltText, HtmlFrmOpts nFrameOpts ); - void writeFrameFormatOptions(HtmlWriter& aHtml, const SwFrameFormat& rFrameFormat, std::u16string_view rAltText, HtmlFrmOpts nFrameOpts); + void writeFrameFormatOptions(HtmlWriter& aHtml, const SwFrameFormat& rFrameFormat, const OUString& rAltText, HtmlFrmOpts nFrameOpts); /// Writes the formatting for tables. void OutCSS1_TableFrameFormatOptions( const SwFrameFormat& rFrameFormat ); @@ -706,7 +706,7 @@ SwHTMLWriter& OutHTML_ImageStart( HtmlWriter& rHtml, SwHTMLWriter&, const SwFram const Size& rRealSize, HtmlFrmOpts nFrameOpts, const char *pMarkType, const ImageMap *pGenImgMap, - std::u16string_view rMimeType = {} ); + const OUString& rMimeType = {} ); SwHTMLWriter& OutHTML_ImageEnd( HtmlWriter& rHtml, SwHTMLWriter& ); SwHTMLWriter& OutHTML_BulletImage( SwHTMLWriter& rWrt, const char *pTag, |