KTextTemplate::OutputStream Class
class KTextTemplate::OutputStreamThe OutputStream class is used to render templates to a QTextStream. More...
Header: | #include <KTextTemplate/OutputStream> |
CMake: | find_package(KF6 REQUIRED COMPONENTS TextTemplate) target_link_libraries(mytarget PRIVATE KF6::TextTemplate) |
Public Functions
OutputStream() | |
OutputStream(QTextStream *stream) | |
virtual | ~OutputStream() |
virtual QSharedPointer<KTextTemplate::OutputStream> | clone(QTextStream *stream) const |
QString | conditionalEscape(const KTextTemplate::SafeString &input) const |
QString | escape(const KTextTemplate::SafeString &input) const |
virtual QString | escape(const QString &input) const |
KTextTemplate::OutputStream & | operator<<(QTextStream *stream) |
KTextTemplate::OutputStream & | operator<<(const KTextTemplate::SafeString &input) |
KTextTemplate::OutputStream & | operator<<(const QString &input) |
Detailed Description
A OutputStream instance may be passed to the render method of a Template to render the template to a stream.
QFile outputFile("./output"); outputFile.open(QFile::WriteOnly); QTextStream tstream( &outputFile ); OutputStream os(&tstream); t->render( &os, &context );
The OutputStream is used to escape the content streamed to it. By default, the escaping is html escaping, converting "&" to "&" for example. If generating non-html output, the escape method may be overriden to perform a different escaping, or non at all.
If overriding the escape method, the clone method must also be overriden to return an OutputStream with the same escaping behaviour.
class NoEscapeStream : public KTextTemplate::OutputStream { public: // ... QString escape( const QString &input ) const { return input; } QSharedPointer<OutputStream> clone( QTextStream *stream ) const { return QSharedPointer<NoEscapeStream>::create( stream ); } };
Member Function Documentation
OutputStream::OutputStream()
Creates a null OutputStream. Content streamed to this OutputStream is sent to /dev/null
[explicit]
OutputStream::OutputStream(QTextStream *stream)
Creates an OutputStream which will stream content to stream with appropriate escaping.
[virtual noexcept]
OutputStream::~OutputStream()
Destructor
[virtual]
QSharedPointer<KTextTemplate::OutputStream> OutputStream::clone(QTextStream *stream) const
Returns a cloned OutputStream with the same filtering behaviour.
QString OutputStream::conditionalEscape(const KTextTemplate::SafeString &input) const
Returns after escaping it, unless input is "safe", in which case, input is returned unmodified.
QString OutputStream::escape(const KTextTemplate::SafeString &input) const
Returns an escaped version of input. Does not write anything to the stream.
[virtual]
QString OutputStream::escape(const QString &input) const
Returns an escaped version of input. Does not write anything to the stream.
KTextTemplate::OutputStream &OutputStream::operator<<(QTextStream *stream)
Reads the content of stream and writes it unmodified to the result stream.
KTextTemplate::OutputStream &OutputStream::operator<<(const KTextTemplate::SafeString &input)
Writes input to the stream after escaping it if necessary.
KTextTemplate::OutputStream &OutputStream::operator<<(const QString &input)
Writes input to the stream after escaping it.