Grantlee  0.5.1
filter.h
1 /*
2  This file is part of the Grantlee template system.
3 
4  Copyright (c) 2009,2010 Stephen Kelly <steveire@gmail.com>
5 
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.1 of the Licence, or (at your option) any later version.
10 
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  Lesser General Public License for more details.
15 
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/>.
18 
19 */
20 
21 // krazy:excludeall=dpointer
22 
23 #ifndef GRANTLEE_FILTER_H
24 #define GRANTLEE_FILTER_H
25 
26 #include "grantlee_core_export.h"
27 #include "outputstream.h"
28 #include "safestring.h"
29 
30 #include <QtCore/QSharedPointer>
31 #include <QtCore/QStringList>
32 #include <QtCore/QVariant>
33 
34 namespace Grantlee
35 {
36 
38 
52 class GRANTLEE_CORE_EXPORT Filter
53 {
54 public:
55 #ifndef Q_QDOC
56  typedef QSharedPointer<Filter> Ptr;
57 #endif
58 
62  virtual ~Filter() {}
63 
64 #ifndef Q_QDOC
65 
68  void setStream( OutputStream *stream ) {
69  m_stream = stream;
70  }
71 #endif
72 
76  SafeString escape( const QString &input ) const {
77  return m_stream->escape( input );
78  }
79 
83  SafeString escape( const SafeString &input ) const {
84  if ( input.isSafe() )
85  return SafeString( m_stream->escape( input ), SafeString::IsSafe );
86  return m_stream->escape( input );
87  }
88 
92  SafeString conditionalEscape( const SafeString &input ) const {
93  if ( !input.isSafe() )
94  return m_stream->escape( input );
95  return input;
96  }
97 
104  virtual QVariant doFilter( const QVariant &input,
105  const QVariant &argument = QVariant(),
106  bool autoescape = false
107  ) const = 0;
108 
112  virtual bool isSafe() const { // krazy:exclude:inline
113  return false;
114  }
115 
116 private:
117 #ifndef Q_QDOC
118  OutputStream *m_stream;
119 #endif
120 };
121 
122 }
123 
124 #endif
The string is safe and requires no further escaping.
Definition: safestring.h:80
virtual ~Filter()
Definition: filter.h:62
bool isSafe() const
virtual bool isSafe() const
Definition: filter.h:112
SafeString escape(const SafeString &input) const
Definition: filter.h:83
Base class for all filters.
Definition: filter.h:52
SafeString conditionalEscape(const SafeString &input) const
Definition: filter.h:92
The OutputStream class is used to render templates to a QTextStream.
Definition: outputstream.h:76
SafeString escape(const QString &input) const
Definition: filter.h:76
A QString wrapper class for containing whether a string is safe or needs to be escaped.
Definition: safestring.h:73