source: trunk/src/xmlpatterns/utils/qpatternistlocale_p.h@ 5

Last change on this file since 5 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 8.2 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtXmlPatterns module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42//
43// W A R N I N G
44// -------------
45//
46// This file is not part of the Qt API. It exists purely as an
47// implementation detail. This header file may change from version to
48// version without notice, or even be removed.
49//
50// We mean it.
51
52#ifndef Patternist_Locale_H
53#define Patternist_Locale_H
54
55#include <QCoreApplication>
56#include <QString>
57#include <QUrl>
58
59#include "qcardinality_p.h"
60#include "qnamepool_p.h"
61#include "qprimitives_p.h"
62
63QT_BEGIN_NAMESPACE
64
65/**
66 * @file
67 * @short Contains functions used for formatting arguments, such as keywords and paths,
68 * in translated strings.
69 *
70 * This file was originally called qpatternistlocale_p.h. However, it broke build on MS
71 * Windows, because it override the locale.h system header.
72 */
73
74namespace QPatternist
75{
76 /**
77 * @short Provides a translation context & functions for the QtXmlPatterns
78 * module.
79 *
80 * This class is not supposed to be instantiated.
81 */
82 class QtXmlPatterns
83 {
84 public:
85 Q_DECLARE_TR_FUNCTIONS(QtXmlPatterns)
86
87 private:
88 /**
89 * No implementation is provided, this class is not supposed to be
90 * instantiated.
91 */
92 inline QtXmlPatterns();
93 Q_DISABLE_COPY(QtXmlPatterns)
94 };
95
96 static inline QString formatKeyword(const QString &keyword)
97 {
98 return QLatin1String("<span class='XQuery-keyword'>") +
99 escape(keyword) +
100 QLatin1String("</span>");
101 }
102
103 /**
104 * @overload
105 */
106 static inline QString formatKeyword(const QStringRef &keyword)
107 {
108 return formatKeyword(keyword.toString());
109 }
110
111 static inline QString formatKeyword(const char *const keyword)
112 {
113 return formatKeyword(QLatin1String(keyword));
114 }
115
116 static inline QString formatKeyword(const QChar keyword)
117 {
118 return formatKeyword(QString(keyword));
119 }
120
121 /**
122 * @short Formats element name.
123 */
124 static inline QString formatElement(const QString &element)
125 {
126 // for the moment we forward to formatKeyword, that will change later
127 return formatKeyword(element);
128 }
129
130 /**
131 * @overload
132 */
133 static inline QString formatElement(const char *const element)
134 {
135 return formatElement(QLatin1String(element));
136 }
137
138 /**
139 * @short Formats attribute name.
140 */
141 static inline QString formatAttribute(const QString &attribute)
142 {
143 // for the moment we forward to formatKeyword, that will change later
144 return formatKeyword(attribute);
145 }
146
147 /**
148 * @overload
149 */
150 static inline QString formatAttribute(const char *const attribute)
151 {
152 return formatAttribute(QLatin1String(attribute));
153 }
154
155 /**
156 * @short Formats ItemType and SequenceType.
157 *
158 * This function is not declared static, because the compiler on target
159 * aix-xlc-64 won't accept it.
160 */
161 template<typename T>
162 inline QString formatType(const NamePool::Ptr &np, const T &type)
163 {
164 Q_ASSERT(type);
165 return QLatin1String("<span class='XQuery-type'>") +
166 escape(type->displayName(np)) +
167 QLatin1String("</span>");
168 }
169
170 /**
171 * @short Formats Cardinality.
172 */
173 static inline QString formatType(const Cardinality &type)
174 {
175 return QLatin1String("<span class='XQuery-type'>") +
176 escape(type.displayName(Cardinality::IncludeExplanation)) +
177 QLatin1String("</span>");
178 }
179
180 /**
181 * @short Formats @p uri as a path to a resource, typically it's a filename
182 * or a URI.
183 */
184 static inline QString formatResourcePath(const QUrl &uri)
185 {
186 const QString normalizedURI(escape(uri.toString(QUrl::RemovePassword)));
187
188 return QLatin1String("<span class='XQuery-filepath'><a href='") +
189 normalizedURI +
190 QLatin1String("'>") +
191 normalizedURI +
192 QLatin1String("</a></span>");
193 }
194
195 /**
196 * @short Formats @p uri for display.
197 *
198 * @note It's not guaranteed that URIs being formatted are valid. That can
199 * be an arbitrary string.
200 */
201 static inline QString formatURI(const QUrl &uri)
202 {
203 return QLatin1String("<span class='XQuery-uri'>") +
204 escape(uri.toString(QUrl::RemovePassword)) +
205 QLatin1String("</span>");
206 }
207
208 /**
209 * @short Formats @p uri, that's considered to be a URI, for display.
210 *
211 * @p uri does not have to be a valid QUrl or valid instance of @c
212 * xs:anyURI.
213 */
214 static inline QString formatURI(const QString &uri)
215 {
216 const QUrl realURI(uri);
217 return formatURI(realURI);
218 }
219
220 static inline QString formatData(const QString &data)
221 {
222 return QLatin1String("<span class='XQuery-data'>") +
223 escape(data) +
224 QLatin1String("</span>");
225 }
226
227 /**
228 * This is an overload, provided for convenience.
229 */
230 static inline QString formatData(const xsInteger data)
231 {
232 return formatData(QString::number(data));
233 }
234
235 /**
236 * This is an overload, provided for convenience.
237 */
238 static inline QString formatData(const char *const data)
239 {
240 return formatData(QLatin1String(data));
241 }
242
243 /**
244 * This is an overload, provided for convenience.
245 */
246 static inline QString formatData(const QLatin1Char &data)
247 {
248 return formatData(QString(data));
249 }
250
251 /**
252 * Formats an arbitrary expression, such as a regular expression
253 * or XQuery query.
254 */
255 static inline QString formatExpression(const QString &expr)
256 {
257 return QLatin1String("<span class='XQuery-expression'>") +
258 escape(expr) +
259 QLatin1String("</span>");
260 }
261
262}
263
264#ifdef Q_NO_TYPESAFE_FLAGS
265#error "Patternist does not compile with Q_NO_TYPESAFE_FLAGS set, because the code uses negative enum values. qglobal.h has typedef uint Flags."
266#endif
267
268#ifdef QT_NO_EXCEPTIONS
269#error "Patternist uses exceptions and cannot be built without."
270#endif
271
272QT_END_NAMESPACE
273#endif
Note: See TracBrowser for help on using the repository browser.