KTextTemplate

filter.h
1/*
2 This file is part of the KTextTemplate library
3
4 SPDX-FileCopyrightText: 2009, 2010 Stephen Kelly <steveire@gmail.com>
5
6 SPDX-License-Identifier: LGPL-2.1-or-later
7
8*/
9
10// krazy:excludeall=dpointer
11
12#ifndef KTEXTTEMPLATE_FILTER_H
13#define KTEXTTEMPLATE_FILTER_H
14
15#include "ktexttemplate_export.h"
16#include "outputstream.h"
17#include "safestring.h"
18
19#include <QSharedPointer>
20#include <QStringList>
21#include <QVariant>
22
23namespace KTextTemplate
24{
25
26/// @headerfile filter.h <KTextTemplate/Filter>
27
28/**
29 @brief Base class for all filters.
30
31 The **%Filter** class can be implemented in plugin libraries to make
32 additional functionality available to templates.
33
34 Developers are required only to implement the @ref doFilter method and
35 integrate the filter as part of a custom plugin, but will never create or
36 access filters directly in application code.
37
38 The FilterExpression class is the access interface to a chain of **%Filter**
39 objects.
40
41 The @ref escape and @ref conditionalEscape methods are available for escaping
42 data where needed.
43
44 @see @ref filters
45
46 @author Stephen Kelly <steveire@gmail.com>
47*/
48class KTEXTTEMPLATE_EXPORT Filter
49{
50public:
51 /**
52 Destructor.
53 */
54 virtual ~Filter();
55
56#ifndef K_DOXYGEN
57 /**
58 FilterExpression makes it possible to access stream methods like escape
59 while resolving.
60 */
61 void setStream(OutputStream *stream);
62#endif
63
64 /**
65 Escapes and returns @p input. The OutputStream::escape method is used to
66 escape @p input.
67 */
68 SafeString escape(const QString &input) const;
69
70 /**
71 Escapes and returns @p input. The OutputStream::escape method is used to
72 escape @p input.
73 */
74 SafeString escape(const SafeString &input) const;
75
76 /**
77 Escapes @p input if not already safe from further escaping and returns it.
78 The OutputStream::escape method is used to escape @p input.
79 */
80 SafeString conditionalEscape(const SafeString &input) const;
81
82 /**
83 Reimplement to filter @p input given @p argument.
84
85 @p autoescape determines whether the autoescape feature is currently on or
86 off. Most filters will not use this.
87
88 @see @ref autoescaping
89 */
90 virtual QVariant doFilter(const QVariant &input, const QVariant &argument = {}, bool autoescape = {}) const = 0;
91
92 /**
93 Reimplement to return whether this filter is safe.
94 */
95 virtual bool isSafe() const;
96
97private:
98#ifndef K_DOXYGEN
99 OutputStream *m_stream;
100#endif
101};
102}
103
104#endif
Base class for all filters.
Definition filter.h:49
virtual QVariant doFilter(const QVariant &input, const QVariant &argument={}, bool autoescape={}) const =0
Reimplement to filter input given argument.
virtual ~Filter()
Destructor.
The OutputStream class is used to render templates to a QTextStream.
A QString wrapper class for containing whether a string is safe or needs to be escaped.
Definition safestring.h:81
The KTextTemplate namespace holds all public KTextTemplate API.
Definition Mainpage.dox:8
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:56:17 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.