2
This file is part of the Grantlee template system.
4
Copyright (c) 2010 Stephen Kelly <steveire@gmail.com>
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Lesser General Public
8
License as published by the Free Software Foundation; either version
9
2 of the Licence, or (at your option) any later version.
11
This library is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
Library General Public License for more details.
16
You should have received a copy of the GNU Lesser General Public
17
License along with this library. If not, see <http://www.gnu.org/licenses/>.
21
#ifndef GRANTLEE_OUTPUTSTREAM_H
22
#define GRANTLEE_OUTPUTSTREAM_H
24
#include <QtCore/QTextStream>
25
#include <QtCore/QSharedPointer>
27
#include "grantlee_core_export.h"
34
/// @headerfile outputstream.h grantlee/outputstream.h
37
@brief The OutputStream class is used to render templates to a QTextStream
39
A OutputStream instance may be passed to the render method of a Template to render
40
the template to a stream.
43
QFile outputFile("./output");
44
outputFile.open(QFile::WriteOnly);
45
QTextStream tstream( &outputFile );
47
OutputStream os(&tstream);
48
t->render( &os, &context );
51
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.
53
If overriding the escape method, the clone method must also be overriden to return an OutputStream with the same escaping behaviour.
56
class NoEscapeStream : public Grantlee::OutputStream
61
QString escape( const QString &input ) const
66
QSharedPointer<OutputStream> clone( QTextStream *stream ) const
68
QSharedPointer<OutputStream> clonedStream = QSharedPointer<OutputStream>( new NoEscapeStream( stream ) );
74
@author Stephen Kelly <steveire@gmail.com>
76
class GRANTLEE_CORE_EXPORT OutputStream
80
Creates a null OutputStream. Content streamed to this OutputStream is sent to /dev/null
85
Creates an OutputStream which will stream content to @p stream with appropriate escaping.
87
explicit OutputStream( QTextStream *stream );
92
virtual ~OutputStream();
95
Returns an escaped version of @p input. Does not write anything to the stream.
97
virtual QString escape( const QString &input ) const;
100
Returns an escaped version of @p input. Does not write anything to the stream.
102
QString escape( const SafeString &input ) const;
105
Returns an cloned OutputStream with the same filtering behaviour.
107
virtual QSharedPointer<OutputStream> clone( QTextStream *stream ) const;
110
Returns @p after escaping it, unless @p input is "safe", in which case, @p input is returned unmodified.
112
QString conditionalEscape( const Grantlee::SafeString &input ) const;
115
Writes @p input to the stream after escaping it.
117
OutputStream& operator<<( const QString &input );
120
Writes @p input to the stream after escaping it if necessary.
122
OutputStream& operator<<( const SafeString &input );
125
Reads the content of @p stream and writes it unmodified to the result stream.
127
OutputStream& operator<<( QTextStream *stream );
130
QTextStream *m_stream;
131
Q_DISABLE_COPY( OutputStream )