KTextTemplate::OutputStream

Search for usage in LXR

KTextTemplate::OutputStream Class Reference

#include <KTextTemplate/OutputStream>

Public Member Functions

 OutputStream ()
 
 OutputStream (QTextStream *stream)
 
virtual ~OutputStream ()
 
virtual QSharedPointer< OutputStreamclone (QTextStream *stream) const
 
QString conditionalEscape (const KTextTemplate::SafeString &input) const
 
virtual QString escape (const QString &input) const
 
QString escape (const SafeString &input) const
 
OutputStreamoperator<< (const QString &input)
 
OutputStreamoperator<< (const SafeString &input)
 
OutputStreamoperator<< (QTextStream *stream)
 

Detailed Description

The OutputStream class is used to render templates to a QTextStream.

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 "&amp;" 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;
}
{
}
};
Author
Stephen Kelly steve[email protected][email protected][email protected]gmail[email protected].com

Definition at line 80 of file outputstream.h.

Constructor & Destructor Documentation

◆ OutputStream() [1/2]

OutputStream::OutputStream ( )

Creates a null OutputStream.

Content streamed to this OutputStream is sent to /dev/null

Definition at line 27 of file outputstream.cpp.

◆ OutputStream() [2/2]

OutputStream::OutputStream ( QTextStream stream)
explicit

Creates an OutputStream which will stream content to stream with appropriate escaping.

Definition at line 32 of file outputstream.cpp.

◆ ~OutputStream()

OutputStream::~OutputStream ( )
virtualdefault

Destructor.

Member Function Documentation

◆ clone()

QSharedPointer< OutputStream > OutputStream::clone ( QTextStream stream) const
virtual

Returns a cloned OutputStream with the same filtering behaviour.

Definition at line 77 of file outputstream.cpp.

◆ conditionalEscape()

QString OutputStream::conditionalEscape ( const KTextTemplate::SafeString input) const

Returns after escaping it, unless input is "safe", in which case, input is returned unmodified.

Definition at line 70 of file outputstream.cpp.

◆ escape() [1/2]

QString OutputStream::escape ( const QString input) const
virtual

Returns an escaped version of input.

Does not write anything to the stream.

Definition at line 39 of file outputstream.cpp.

◆ escape() [2/2]

QString OutputStream::escape ( const SafeString input) const

Returns an escaped version of input.

Does not write anything to the stream.

Definition at line 65 of file outputstream.cpp.

◆ operator<<() [1/3]

OutputStream & OutputStream::operator<< ( const QString input)

Writes input to the stream after escaping it.

Definition at line 82 of file outputstream.cpp.

◆ operator<<() [2/3]

OutputStream & OutputStream::operator<< ( const SafeString input)

Writes input to the stream after escaping it if necessary.

Definition at line 89 of file outputstream.cpp.

◆ operator<<() [3/3]

OutputStream & OutputStream::operator<< ( QTextStream stream)

Reads the content of stream and writes it unmodified to the result stream.

Definition at line 107 of file outputstream.cpp.


The documentation for this class was generated from the following files:
QSharedPointer< T > create(Args &&... args)
OutputStream()
Creates a null OutputStream.
virtual QString escape(const QString &input) const
Returns an escaped version of input.
virtual QSharedPointer< OutputStream > clone(QTextStream *stream) const
Returns a cloned OutputStream with the same filtering behaviour.
The OutputStream class is used to render templates to a QTextStream.
Definition: outputstream.h:80
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon May 8 2023 04:01:03 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.