Qt 4.8
qpatternistlocale_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
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 
64 
71 namespace QPatternist
72 {
80  {
81  public:
83 
84  private:
89  inline QtXmlPatterns();
91  };
92 
93  // don't make this function static, otherwise xlC 7 cannot find it
94  inline QString formatKeyword(const QString &keyword)
95  {
96  return QLatin1String("<span class='XQuery-keyword'>") +
97  escape(keyword) +
98  QLatin1String("</span>");
99  }
100 
104  static inline QString formatKeyword(const QStringRef &keyword)
105  {
106  return formatKeyword(keyword.toString());
107  }
108 
109  static inline QString formatKeyword(const char *const keyword)
110  {
111  return formatKeyword(QLatin1String(keyword));
112  }
113 
114  static inline QString formatKeyword(const QChar keyword)
115  {
116  return formatKeyword(QString(keyword));
117  }
118 
122  static inline QString formatElement(const QString &element)
123  {
124  // for the moment we forward to formatKeyword, that will change later
125  return formatKeyword(element);
126  }
127 
131  static inline QString formatElement(const char *const element)
132  {
133  return formatElement(QLatin1String(element));
134  }
135 
139  static inline QString formatAttribute(const QString &attribute)
140  {
141  // for the moment we forward to formatKeyword, that will change later
142  return formatKeyword(attribute);
143  }
144 
148  static inline QString formatAttribute(const char *const attribute)
149  {
150  return formatAttribute(QLatin1String(attribute));
151  }
152 
159  template<typename T>
160  inline QString formatType(const NamePool::Ptr &np, const T &type)
161  {
162  Q_ASSERT(type);
163  return QLatin1String("<span class='XQuery-type'>") +
164  escape(type->displayName(np)) +
165  QLatin1String("</span>");
166  }
167 
171  static inline QString formatType(const NamePool::Ptr &np, const QXmlName &name)
172  {
173  return QLatin1String("<span class='XQuery-type'>") +
174  escape(np->displayName(name)) +
175  QLatin1String("</span>");
176  }
177 
181  static inline QString formatType(const Cardinality &type)
182  {
183  return QLatin1String("<span class='XQuery-type'>") +
185  QLatin1String("</span>");
186  }
187 
192  static inline QString formatResourcePath(const QUrl &uri)
193  {
194  const QString normalizedURI(escape(uri.toString(QUrl::RemovePassword)));
195 
196  return QLatin1String("<span class='XQuery-filepath'><a href='") +
197  normalizedURI +
198  QLatin1String("'>") +
199  normalizedURI +
200  QLatin1String("</a></span>");
201  }
202 
209  static inline QString formatURI(const QUrl &uri)
210  {
211  return QLatin1String("<span class='XQuery-uri'>") +
213  QLatin1String("</span>");
214  }
215 
222  static inline QString formatURI(const QString &uri)
223  {
224  const QUrl realURI(uri);
225  return formatURI(realURI);
226  }
227 
228  static inline QString formatData(const QString &data)
229  {
230  return QLatin1String("<span class='XQuery-data'>") +
231  escape(data) +
232  QLatin1String("</span>");
233  }
234 
238  static inline QString formatData(const xsInteger data)
239  {
240  return formatData(QString::number(data));
241  }
242 
246  static inline QString formatData(const char *const data)
247  {
248  return formatData(QLatin1String(data));
249  }
250 
254  static inline QString formatData(const QLatin1Char &data)
255  {
256  return formatData(QString(data));
257  }
258 
263  static inline QString formatExpression(const QString &expr)
264  {
265  return QLatin1String("<span class='XQuery-expression'>") +
266  escape(expr) +
267  QLatin1String("</span>");
268  }
269 
270 }
271 
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."
274 #endif
275 
276 #ifdef QT_NO_EXCEPTIONS
277 #error "Patternist uses exceptions and cannot be built without."
278 #endif
279 
281 #endif
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
QString toString() const
Returns a copy of the string reference as a QString object.
Definition: qstring.cpp:8653
int type
Definition: qmetatype.cpp:239
QString Q_AUTOTEST_EXPORT escape(const QString &input)
Similar to Qt::escape(), but also escapes apostrophes and quotes, such that the result is suitable as...
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
static QString formatResourcePath(const QUrl &uri)
Formats uri as a path to a resource, typically it&#39;s a filename or a URI.
QString displayName(const CustomizeDisplayName explanation) const
QString toString(FormattingOptions options=None) const
Returns the human-displayable string representation of the URL.
Definition: qurl.cpp:5896
QString formatKeyword(const QString &keyword)
Provides a translation context & functions for the QtXmlPatterns module.
qint64 xsInteger
QString formatType(const NamePool::Ptr &np, const T &type)
Formats ItemType and SequenceType.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static QString formatElement(const QString &element)
Formats element name.
const char * name
The namespace for the internal API of QtXmlPatterns.
static const char * data(const QByteArray &arr)
static QString formatData(const QString &data)
The QStringRef class provides a thin wrapper around QString substrings.
Definition: qstring.h:1099
The QXmlName class represents the name of an XML node, in an efficient, namespace-aware way...
Definition: qxmlname.h:58
static QString formatExpression(const QString &expr)
Contains enumerators and typedefs applying for Patternist on a global scale, as well as central docum...
Represents a cardinality, a possible , often represented by occurrence indicators.
static QString formatURI(const NamePool::Ptr &np, const QXmlName::NamespaceCode &uri)
Formats uri, that&#39;s considered to be a URI, for display.
Definition: qanyuri_p.h:202
static QString formatAttribute(const QString &attribute)
Formats attribute name.
#define Q_DECLARE_TR_FUNCTIONS(context)
The Q_DECLARE_TR_FUNCTIONS() macro declares and implements two translation functions, tr() and trUtf8(), with these signatures:
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55