1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
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.
52 #ifndef Patternist_Locale_H
53 #define Patternist_Locale_H
55 #include <QCoreApplication>
59 #include "qcardinality_p.h"
60 #include "qnamepool_p.h"
61 #include "qprimitives_p.h"
67 * @short Contains functions used for formatting arguments, such as keywords and paths,
68 * in translated strings.
74 * @short Provides a translation context & functions for the QtXmlPatterns
77 * This class is not supposed to be instantiated.
82 Q_DECLARE_TR_FUNCTIONS(QtXmlPatterns)
86 * No implementation is provided, this class is not supposed to be
89 inline QtXmlPatterns();
90 Q_DISABLE_COPY(QtXmlPatterns)
93 // don't make this function static, otherwise xlC 7 cannot find it
94 inline QString formatKeyword(const QString &keyword)
96 return QLatin1String("<span class='XQuery-keyword'>") +
98 QLatin1String("</span>");
104 static inline QString formatKeyword(const QStringRef &keyword)
106 return formatKeyword(keyword.toString());
109 static inline QString formatKeyword(const char *const keyword)
111 return formatKeyword(QLatin1String(keyword));
114 static inline QString formatKeyword(const QChar keyword)
116 return formatKeyword(QString(keyword));
120 * @short Formats element name.
122 static inline QString formatElement(const QString &element)
124 // for the moment we forward to formatKeyword, that will change later
125 return formatKeyword(element);
131 static inline QString formatElement(const char *const element)
133 return formatElement(QLatin1String(element));
137 * @short Formats attribute name.
139 static inline QString formatAttribute(const QString &attribute)
141 // for the moment we forward to formatKeyword, that will change later
142 return formatKeyword(attribute);
148 static inline QString formatAttribute(const char *const attribute)
150 return formatAttribute(QLatin1String(attribute));
154 * @short Formats ItemType and SequenceType.
156 * This function is not declared static, because the compiler on target
157 * aix-xlc-64 won't accept it.
160 inline QString formatType(const NamePool::Ptr &np, const T &type)
163 return QLatin1String("<span class='XQuery-type'>") +
164 escape(type->displayName(np)) +
165 QLatin1String("</span>");
169 * @short Formats name of any type.
171 static inline QString formatType(const NamePool::Ptr &np, const QXmlName &name)
173 return QLatin1String("<span class='XQuery-type'>") +
174 escape(np->displayName(name)) +
175 QLatin1String("</span>");
179 * @short Formats Cardinality.
181 static inline QString formatType(const Cardinality &type)
183 return QLatin1String("<span class='XQuery-type'>") +
184 escape(type.displayName(Cardinality::IncludeExplanation)) +
185 QLatin1String("</span>");
189 * @short Formats @p uri as a path to a resource, typically it's a filename
192 static inline QString formatResourcePath(const QUrl &uri)
194 const QString normalizedURI(escape(uri.toString(QUrl::RemovePassword)));
196 return QLatin1String("<span class='XQuery-filepath'><a href='") +
198 QLatin1String("'>") +
200 QLatin1String("</a></span>");
204 * @short Formats @p uri for display.
206 * @note It's not guaranteed that URIs being formatted are valid. That can
207 * be an arbitrary string.
209 static inline QString formatURI(const QUrl &uri)
211 return QLatin1String("<span class='XQuery-uri'>") +
212 escape(uri.toString(QUrl::RemovePassword)) +
213 QLatin1String("</span>");
217 * @short Formats @p uri, that's considered to be a URI, for display.
219 * @p uri does not have to be a valid QUrl or valid instance of @c
222 static inline QString formatURI(const QString &uri)
224 const QUrl realURI(uri);
225 return formatURI(realURI);
228 static inline QString formatData(const QString &data)
230 return QLatin1String("<span class='XQuery-data'>") +
232 QLatin1String("</span>");
236 * This is an overload, provided for convenience.
238 static inline QString formatData(const xsInteger data)
240 return formatData(QString::number(data));
244 * This is an overload, provided for convenience.
246 static inline QString formatData(const char *const data)
248 return formatData(QLatin1String(data));
252 * This is an overload, provided for convenience.
254 static inline QString formatData(const QLatin1Char &data)
256 return formatData(QString(data));
260 * Formats an arbitrary expression, such as a regular expression
263 static inline QString formatExpression(const QString &expr)
265 return QLatin1String("<span class='XQuery-expression'>") +
267 QLatin1String("</span>");
272 #ifdef Q_NO_TYPESAFE_FLAGS
273 #error "Patternist does not compile with Q_NO_TYPESAFE_FLAGS set, because the code uses negative enum values. qglobal.h has typedef uint Flags."
276 #ifdef QT_NO_EXCEPTIONS
277 #error "Patternist uses exceptions and cannot be built without."