diff options
-rw-r--r-- | include/svtools/HtmlWriter.hxx | 4 | ||||
-rw-r--r-- | svtools/qa/unit/testHtmlWriter.cxx | 17 | ||||
-rw-r--r-- | svtools/source/svhtml/HtmlWriter.cxx | 11 |
3 files changed, 31 insertions, 1 deletions
diff --git a/include/svtools/HtmlWriter.hxx b/include/svtools/HtmlWriter.hxx index a842df4870a9..25030f6dffe8 100644 --- a/include/svtools/HtmlWriter.hxx +++ b/include/svtools/HtmlWriter.hxx @@ -27,6 +27,7 @@ private: bool mbElementOpen; bool mbContentWritten; + bool mbCharactersWritten; bool mbPrettyPrint; /// XML namespace, in case of XHTML. OString maNamespace; @@ -52,6 +53,9 @@ public: void single(const OString& aContent); void endAttribute(); + + /// Writes character data. + void characters(const OString& rChars); }; #endif diff --git a/svtools/qa/unit/testHtmlWriter.cxx b/svtools/qa/unit/testHtmlWriter.cxx index bdb5c5814fd7..18cb409ff37b 100644 --- a/svtools/qa/unit/testHtmlWriter.cxx +++ b/svtools/qa/unit/testHtmlWriter.cxx @@ -41,6 +41,7 @@ public: void testNested(); void testNamespace(); void testAttributeValues(); + void testCharacters(); CPPUNIT_TEST_SUITE(Test); CPPUNIT_TEST(testSingleElement); @@ -50,6 +51,7 @@ public: CPPUNIT_TEST(testNested); CPPUNIT_TEST(testNamespace); CPPUNIT_TEST(testAttributeValues); + CPPUNIT_TEST(testCharacters); CPPUNIT_TEST_SUITE_END(); }; @@ -190,6 +192,21 @@ void Test::testAttributeValues() CPPUNIT_ASSERT_EQUAL(OString("<abc one=\"one\" two=\"two\" three=\"12\"/>"), aString); } +void Test::testCharacters() +{ + SvMemoryStream aStream; + + HtmlWriter aHtml(aStream); + aHtml.prettyPrint(false); + aHtml.start("abc"); + aHtml.characters("hello"); + aHtml.end(); + + OString aString = extractFromStream(aStream); + + CPPUNIT_ASSERT_EQUAL(OString("<abc>hello</abc>"), aString); +} + CPPUNIT_TEST_SUITE_REGISTRATION(Test); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/svtools/source/svhtml/HtmlWriter.cxx b/svtools/source/svhtml/HtmlWriter.cxx index 499aa7ed8ab0..631a56e3e1f1 100644 --- a/svtools/source/svhtml/HtmlWriter.cxx +++ b/svtools/source/svhtml/HtmlWriter.cxx @@ -15,6 +15,7 @@ HtmlWriter::HtmlWriter(SvStream& rStream, const OString& rNamespace) : mrStream(rStream), mbElementOpen(false), mbContentWritten(false), + mbCharactersWritten(false), mbPrettyPrint(true) { if (!rNamespace.isEmpty()) @@ -83,7 +84,7 @@ void HtmlWriter::flushStack() void HtmlWriter::end() { - if (mbElementOpen) + if (mbElementOpen && !mbCharactersWritten) { mrStream.WriteCharPtr("/>"); if (mbPrettyPrint) @@ -107,6 +108,7 @@ void HtmlWriter::end() maElementStack.pop_back(); mbElementOpen = false; mbContentWritten = false; + mbCharactersWritten = false; } void HtmlWriter::attribute(const OString &aAttribute, const OString& aValue) @@ -146,5 +148,12 @@ void HtmlWriter::attribute(const OString& aAttribute) } } +void HtmlWriter::characters(const OString& rChars) +{ + if (!mbCharactersWritten) + mrStream.WriteCharPtr(">"); + mrStream.WriteOString(rChars); + mbCharactersWritten = true; +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |