1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtXmlPatterns module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40//
41// W A R N I N G
42// -------------
43//
44// This file is not part of the Qt API. It exists purely as an
45// implementation detail. This header file may change from version to
46// version without notice, or even be removed.
47//
48// We mean it.
49
50#ifndef Patternist_StringValueFNs_H
51#define Patternist_StringValueFNs_H
52
53#include <QByteArray>
54
55#include <private/qfunctioncall_p.h>
56
57/**
58 * @file
59 * @short Contains classes implementing the functions found in
60 * <a href="http://www.w3.org/TR/xpath-functions/#string-value-functions">XQuery 1.0 and
61 * XPath 2.0 Functions and Operators, 7.4 Functions on AtomicString Values</a>.
62 *
63 * @ingroup Patternist_functions
64 */
65
66QT_BEGIN_NAMESPACE
67
68namespace QPatternist
69{
70
71 /**
72 * @short Implements the function <tt>fn:concat()</tt>.
73 *
74 * @ingroup Patternist_functions
75 * @author Frans Englich <frans.englich@nokia.com>
76 */
77 class ConcatFN : public FunctionCall
78 {
79 public:
80 virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const;
81 };
82
83 /**
84 * @short Implements the function <tt>fn:string-join()</tt>.
85 *
86 * @ingroup Patternist_functions
87 * @author Frans Englich <frans.englich@nokia.com>
88 */
89 class StringJoinFN : public FunctionCall
90 {
91 public:
92 virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const;
93
94 /**
95 * Optimization: when the cardinality of the sequence of items to join
96 * cannot be two or more, we have no effect and therefore rewrite
97 * ourselves to our first operand.
98 */
99 virtual Expression::Ptr compress(const StaticContext::Ptr &context);
100 };
101
102 /**
103 * @short Implements the function <tt>fn:substring()</tt>.
104 *
105 * @ingroup Patternist_functions
106 * @author Frans Englich <frans.englich@nokia.com>
107 */
108 class SubstringFN : public FunctionCall
109 {
110 public:
111 virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const;
112 };
113
114 /**
115 * @short Implements the function <tt>fn:string-length()</tt>.
116 *
117 * @ingroup Patternist_functions
118 * @author Frans Englich <frans.englich@nokia.com>
119 */
120 class StringLengthFN : public FunctionCall
121 {
122 public:
123 virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const;
124 };
125
126 /**
127 * @short Implements the function <tt>fn:normalize-space()</tt>.
128 *
129 * @ingroup Patternist_functions
130 * @author Frans Englich <frans.englich@nokia.com>
131 */
132 class NormalizeSpaceFN : public FunctionCall
133 {
134 public:
135 virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const;
136 };
137
138 /**
139 * @short Implements the function <tt>fn:normalize-unicode()</tt>.
140 *
141 * What perhaps can be said significant with the implementation, is that it
142 * attempts to determine the normalization form at compile time, in order to
143 * reduce string work at runtime.
144 *
145 * @ingroup Patternist_functions
146 * @author Frans Englich <frans.englich@nokia.com>
147 */
148 class NormalizeUnicodeFN : public FunctionCall
149 {
150 public:
151 /**
152 * Initializes private data.
153 */
154 NormalizeUnicodeFN();
155 virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const;
156 virtual Expression::Ptr compress(const StaticContext::Ptr &context);
157
158 private:
159 int determineNormalizationForm(const DynamicContext::Ptr &context) const;
160 QString::NormalizationForm m_normForm;
161 };
162
163 /**
164 * @short Implements the function <tt>fn:upper-case()</tt>.
165 *
166 * @ingroup Patternist_functions
167 * @author Frans Englich <frans.englich@nokia.com>
168 */
169 class UpperCaseFN : public FunctionCall
170 {
171 public:
172 virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const;
173 };
174
175 /**
176 * @short Implements the function <tt>fn:lower-case()</tt>.
177 *
178 * @short Implements the function <tt>fn:concat()</tt>.
179 * @ingroup Patternist_functions
180 * @author Frans Englich <frans.englich@nokia.com>
181 */
182 class LowerCaseFN : public FunctionCall
183 {
184 public:
185 virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const;
186 };
187
188 /**
189 * @short Implements the function <tt>fn:translate()</tt>.
190 *
191 * @ingroup Patternist_functions
192 * @author Frans Englich <frans.englich@nokia.com>
193 */
194 class TranslateFN : public FunctionCall
195 {
196 public:
197 virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const;
198 };
199
200 /**
201 * @short Provides functionality for encoding strings. Sub-classed by various
202 * function implementations.
203 *
204 * @ingroup Patternist_functions
205 * @author Frans Englich <frans.englich@nokia.com>
206 */
207 class EncodeString : public FunctionCall
208 {
209 public:
210 /**
211 * Evaluates its first operand. If it is the empty sequence, an empty string
212 * is returned. Otherwise, the item's string value is returned percent encoded
213 * as specified in this class's constructor.
214 */
215 virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const;
216
217 protected:
218 /**
219 * Encodes its operand with QUrl::toPercentEncoding(), with @p includeChars as
220 * the characters to encode, and @p excludeChars as the characters to not encode.
221 */
222 EncodeString(const QByteArray &excludeChars, const QByteArray &includeChars);
223
224 private:
225 const QByteArray m_excludeChars;
226 const QByteArray m_includeChars;
227 };
228
229 /**
230 * @short Implements the function <tt>fn:encode-for-uri()</tt>.
231 *
232 * @ingroup Patternist_functions
233 * @author Frans Englich <frans.englich@nokia.com>
234 */
235 class EncodeForURIFN : public EncodeString
236 {
237 public:
238 /**
239 * Performs internal initialization.
240 */
241 EncodeForURIFN();
242
243 private:
244 static const char *const include;
245 };
246
247 /**
248 * @short Implements the function <tt>fn:iri-to-uri()</tt>.
249 *
250 * @ingroup Patternist_functions
251 * @author Frans Englich <frans.englich@nokia.com>
252 */
253 class IriToURIFN : public EncodeString
254 {
255 public:
256 /**
257 * Performs internal initialization.
258 */
259 IriToURIFN();
260
261 private:
262 static const char *const exclude;
263 };
264
265 /**
266 * @short Implements the function <tt>fn:escape-html-uri()</tt>.
267 *
268 * @ingroup Patternist_functions
269 * @author Frans Englich <frans.englich@nokia.com>
270 */
271 class EscapeHtmlURIFN : public EncodeString
272 {
273 public:
274 /**
275 * Performs internal initialization.
276 */
277 EscapeHtmlURIFN();
278
279 private:
280 static const char *const include;
281 static const char *const exclude;
282 };
283}
284
285QT_END_NAMESPACE
286
287#endif
288

source code of qtxmlpatterns/src/xmlpatterns/functions/qstringvaluefns_p.h