diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-03-16 20:50:27 +0100 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-04-06 22:02:11 +0200 |
commit | 2480ded80ed3b6e75d4cfb92dbe003000a685820 (patch) | |
tree | 5415c399d692e437d63692f019aec38b16515d92 /svtools/source/svhtml | |
parent | ee0b9f8df684c743d17880c5b7e1e69504c27cc1 (diff) |
HtmlWriter: add prettyPrint option, instance variables
Change-Id: I6a29e91cc2f328ccbd01b617b39dc9275332d1f0
Diffstat (limited to 'svtools/source/svhtml')
-rw-r--r-- | svtools/source/svhtml/HtmlWriter.cxx | 105 |
1 files changed, 63 insertions, 42 deletions
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('"'); } } |