Grantlee 5.3.0

Public Member Functions | List of all members
Grantlee::OutputStream Class Reference

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

`#include <grantlee/outputstream.h>`

## Public Member Functions
| OutputStream ()
| OutputStream (QTextStream *stream)
virtual | ~OutputStream ()
virtual QSharedPointer< OutputStream > | clone (QTextStream *stream) const
QString | conditionalEscape (const Grantlee::SafeString &input) const
virtual QString | escape (const QString &input) const
QString | escape (const SafeString &input) const
OutputStream & | operator<< (const QString &input)
OutputStream & | operator<< (const SafeString &input)
OutputStream & | operator<< (QTextStream *stream)

## 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 );
Grantlee::OutputStream
The OutputStream class is used to render templates to a QTextStream.
Definition: outputstream.h:81

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 Grantlee::OutputStream
{
public:
// ...
QString escape( const QString &input ) const
{
return input;
}
QSharedPointer<OutputStream> clone( QTextStream *stream ) const
{
return QSharedPointer<NoEscapeStream>::create( stream );
}
};

Author
  Stephen Kelly steve.nosp@m.ire@.nosp@m.gmail.nosp@m..com

Definition at line 80 of file outputstream.h.

## Constructor & Destructor Documentation

## ◆ OutputStream() [1/2]

Grantlee::OutputStream::OutputStream | ( |  | ) |

Creates a null OutputStream. Content streamed to this OutputStream is sent to `/dev/null`

## ◆ OutputStream() [2/2]

Grantlee::OutputStream::OutputStream | ( | QTextStream * | stream | ) |
| explicit

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

## ◆ ~OutputStream()

virtual Grantlee::OutputStream::~OutputStream | ( |  | ) |
| virtual

Destructor

## Member Function Documentation

## ◆ clone()

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

Returns a cloned OutputStream with the same filtering behaviour.

## ◆ conditionalEscape()

QString Grantlee::OutputStream::conditionalEscape | ( | const Grantlee::SafeString & | input | ) | const

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

## ◆ escape() [1/2]

virtual QString Grantlee::OutputStream::escape | ( | const QString & | input | ) | const
| virtual

Returns an escaped version of `input`. Does not write anything to the stream.

## ◆ escape() [2/2]

QString Grantlee::OutputStream::escape | ( | const SafeString & | input | ) | const

Returns an escaped version of `input`. Does not write anything to the stream.

## ◆ operator<<() [1/3]

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

Writes `input` to the stream after escaping it.

## ◆ operator<<() [2/3]

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

Writes `input` to the stream after escaping it if necessary.

## ◆ operator<<() [3/3]

OutputStream & Grantlee::OutputStream::operator<< | ( | QTextStream * | stream | ) |

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