diff options
-rw-r--r-- | include/svtools/HtmlWriter.hxx | 12 | ||||
-rw-r--r-- | svtools/source/svhtml/HtmlWriter.cxx | 105 |
2 files changed, 71 insertions, 46 deletions
diff --git a/include/svtools/HtmlWriter.hxx b/include/svtools/HtmlWriter.hxx index 7bcb2387947e..acfeb651266c 100644 --- a/include/svtools/HtmlWriter.hxx +++ b/include/svtools/HtmlWriter.hxx @@ -19,20 +19,24 @@ class SVT_DLLPUBLIC HtmlWriter { private: - std::vector<OString> mElementStack; - SvStream& mStream; + std::vector<OString> maElementStack; + SvStream& mrStream; - bool mElementOpen; - bool mContentWritten; + bool mbElementOpen; + bool mbContentWritten; + bool mbPrettyPrint; public: HtmlWriter(SvStream& rStream); virtual ~HtmlWriter(); + void prettyPrint(bool bChoice); + void start(OString aElement); void end(); void write(OString aContent); void attribute(OString aAttribute, OString aValue); + void single(OString aContent); void endAttribute(); }; diff --git a/svtools/source/svhtml/HtmlWriter.cxx b/svtools/source/svhtml/HtmlWriter.cxx index 36a3a4feb19b..e107bee175cb 100644 --- a/svtools/source/svhtml/HtmlWriter.cxx +++ b/svtools/source/svhtml/HtmlWriter.cxx @@ -11,89 +11,110 @@ #include <svtools/HtmlWriter.hxx> HtmlWriter::HtmlWriter(SvStream& rStream) : - mStream(rStream), - mElementOpen(false), - mContentWritten(false) + mrStream(rStream), + mbElementOpen(false), + mbContentWritten(false), + mbPrettyPrint(true) {} HtmlWriter::~HtmlWriter() {} +void HtmlWriter::prettyPrint(bool bChoice) +{ + mbPrettyPrint = bChoice; +} + void HtmlWriter::start(OString aElement) { - if (mElementOpen) + if (mbElementOpen) + { + mrStream.WriteChar('>'); + if (!mbContentWritten && mbPrettyPrint) + mrStream.WriteChar('\n'); + mbContentWritten = false; + } + maElementStack.push_back(aElement); + + if (mbPrettyPrint) { - mStream.WriteChar('>'); - if (!mContentWritten) - mStream.WriteChar('\n'); - mContentWritten = false; + for(size_t i = 0; i < maElementStack.size() - 1; i++) + { + mrStream.WriteCharPtr(" "); + } } - mElementStack.push_back(aElement); - for(size_t i = 0; i < mElementStack.size() - 1; i++) - mStream.WriteCharPtr(" "); + mrStream.WriteChar('<'); + mrStream.WriteOString(aElement); + mbElementOpen = true; +} - mStream.WriteChar('<'); - mStream.WriteOString(aElement); - mElementOpen = true; +void HtmlWriter::single(OString aContent) +{ + start(aContent); + end(); } void HtmlWriter::endAttribute() { - if (mElementOpen) + if (mbElementOpen) { - mStream.WriteCharPtr(" />"); - mStream.WriteCharPtr("\n"); - mElementOpen = false; + mrStream.WriteCharPtr("/>"); + if (mbPrettyPrint) + mrStream.WriteCharPtr("\n"); + mbElementOpen = false; } } void HtmlWriter::end() { - if (mElementOpen) + if (mbElementOpen) { - mStream.WriteCharPtr(" />"); - mStream.WriteCharPtr("\n"); + mrStream.WriteCharPtr("/>"); + if (mbPrettyPrint) + mrStream.WriteCharPtr("\n"); } else { - if (!mContentWritten) + if (!mbContentWritten && mbPrettyPrint) { - for(size_t i = 0; i < mElementStack.size() - 1; i++) + for(size_t i = 0; i < maElementStack.size() - 1; i++) { - mStream.WriteCharPtr(" "); + mrStream.WriteCharPtr(" "); } } - mStream.WriteCharPtr("</"); - mStream.WriteOString(mElementStack.back()); - mStream.WriteCharPtr(">\n"); + mrStream.WriteCharPtr("</"); + mrStream.WriteOString(maElementStack.back()); + mrStream.WriteCharPtr(">"); + if (mbPrettyPrint) + mrStream.WriteCharPtr("\n"); } - mElementStack.pop_back(); - mElementOpen = false; - mContentWritten = false; + maElementStack.pop_back(); + mbElementOpen = false; + mbContentWritten = false; } void HtmlWriter::write(OString aContent) { - if (mElementOpen) + if (mbElementOpen) { - mStream.WriteChar('>'); - mElementOpen = false; + mrStream.WriteChar('>'); + mbElementOpen = false; } - mContentWritten = true; - mStream.WriteOString(aContent); + mbContentWritten = true; + mrStream.WriteOString(aContent); } void HtmlWriter::attribute(OString aAttribute, OString aValue) { - if (mElementOpen && !aAttribute.isEmpty() && !aValue.isEmpty()) + if (mbElementOpen && !aAttribute.isEmpty() && !aValue.isEmpty()) { - mStream.WriteChar(' '); - mStream.WriteOString(aAttribute); - mStream.WriteChar('='); - mStream.WriteChar('"'); - mStream.WriteOString(aValue); - mStream.WriteChar('"'); + mrStream.WriteChar(' '); + mrStream.WriteOString(aAttribute); + mrStream.WriteChar('='); + mrStream.WriteChar('"'); + mrStream.WriteOString(aValue); + mrStream.WriteChar('"'); } } |