| 1 |
/**************************************************************************** |
| 2 |
** |
| 3 |
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). |
| 4 |
** All rights reserved. |
| 5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
| 6 |
** |
| 7 |
** This file is part of the QtXmlPatterns module of the Qt Toolkit. |
| 8 |
** |
| 9 |
** $QT_BEGIN_LICENSE:LGPL$ |
| 10 |
** GNU Lesser General Public License Usage |
| 11 |
** This file may be used under the terms of the GNU Lesser General Public |
| 12 |
** License version 2.1 as published by the Free Software Foundation and |
| 13 |
** appearing in the file LICENSE.LGPL included in the packaging of this |
| 14 |
** file. Please review the following information to ensure the GNU Lesser |
| 15 |
** General Public License version 2.1 requirements will be met: |
| 16 |
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
| 17 |
** |
| 18 |
** In addition, as a special exception, Nokia gives you certain additional |
| 19 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
| 20 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
| 21 |
** |
| 22 |
** GNU General Public License Usage |
| 23 |
** Alternatively, this file may be used under the terms of the GNU General |
| 24 |
** Public License version 3.0 as published by the Free Software Foundation |
| 25 |
** and appearing in the file LICENSE.GPL included in the packaging of this |
| 26 |
** file. Please review the following information to ensure the GNU General |
| 27 |
** Public License version 3.0 requirements will be met: |
| 28 |
** http://www.gnu.org/copyleft/gpl.html. |
| 29 |
** |
| 30 |
** Other Usage |
| 31 |
** Alternatively, this file may be used in accordance with the terms and |
| 32 |
** conditions contained in a signed written agreement between you and Nokia. |
| 33 |
** |
| 34 |
** |
| 35 |
** |
| 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 |
|
| 63 |
QT_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 |
|
| 71 |
namespace QPatternist |
| 72 |
{ |
| 73 |
/** |
| 74 |
* @short Provides a translation context & functions for the QtXmlPatterns |
| 75 |
* module. |
| 76 |
* |
| 77 |
* This class is not supposed to be instantiated. |
| 78 |
*/ |
| 79 |
class QtXmlPatterns |
| 80 |
{ |
| 81 |
public: |
| 82 |
Q_DECLARE_TR_FUNCTIONS(QtXmlPatterns) |
| 83 |
|
| 84 |
private: |
| 85 |
/** |
| 86 |
* No implementation is provided, this class is not supposed to be |
| 87 |
* instantiated. |
| 88 |
*/ |
| 89 |
inline QtXmlPatterns(); |
| 90 |
Q_DISABLE_COPY(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 |
|
| 101 |
/** |
| 102 |
* @overload |
| 103 |
*/ |
| 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 |
|
| 119 |
/** |
| 120 |
* @short Formats element name. |
| 121 |
*/ |
| 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 |
|
| 128 |
/** |
| 129 |
* @overload |
| 130 |
*/ |
| 131 |
static inline QString formatElement(const char *const element) |
| 132 |
{ |
| 133 |
return formatElement(QLatin1String(element)); |
| 134 |
} |
| 135 |
|
| 136 |
/** |
| 137 |
* @short Formats attribute name. |
| 138 |
*/ |
| 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 |
|
| 145 |
/** |
| 146 |
* @overload |
| 147 |
*/ |
| 148 |
static inline QString formatAttribute(const char *const attribute) |
| 149 |
{ |
| 150 |
return formatAttribute(QLatin1String(attribute)); |
| 151 |
} |
| 152 |
|
| 153 |
/** |
| 154 |
* @short Formats ItemType and SequenceType. |
| 155 |
* |
| 156 |
* This function is not declared static, because the compiler on target |
| 157 |
* aix-xlc-64 won't accept it. |
| 158 |
*/ |
| 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 |
|
| 168 |
/** |
| 169 |
* @short Formats name of any type. |
| 170 |
*/ |
| 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 |
|
| 178 |
/** |
| 179 |
* @short Formats Cardinality. |
| 180 |
*/ |
| 181 |
static inline QString formatType(const Cardinality &type) |
| 182 |
{ |
| 183 |
return QLatin1String("<span class='XQuery-type'>") + |
| 184 |
escape(type.displayName(Cardinality::IncludeExplanation)) + |
| 185 |
QLatin1String("</span>"); |
| 186 |
} |
| 187 |
|
| 188 |
/** |
| 189 |
* @short Formats @p uri as a path to a resource, typically it's a filename |
| 190 |
* or a URI. |
| 191 |
*/ |
| 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 |
|
| 203 |
/** |
| 204 |
* @short Formats @p uri for display. |
| 205 |
* |
| 206 |
* @note It's not guaranteed that URIs being formatted are valid. That can |
| 207 |
* be an arbitrary string. |
| 208 |
*/ |
| 209 |
static inline QString formatURI(const QUrl &uri) |
| 210 |
{ |
| 211 |
return QLatin1String("<span class='XQuery-uri'>") + |
| 212 |
escape(uri.toString(QUrl::RemovePassword)) + |
| 213 |
QLatin1String("</span>"); |
| 214 |
} |
| 215 |
|
| 216 |
/** |
| 217 |
* @short Formats @p uri, that's considered to be a URI, for display. |
| 218 |
* |
| 219 |
* @p uri does not have to be a valid QUrl or valid instance of @c |
| 220 |
* xs:anyURI. |
| 221 |
*/ |
| 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 |
|
| 235 |
/** |
| 236 |
* This is an overload, provided for convenience. |
| 237 |
*/ |
| 238 |
static inline QString formatData(const xsInteger data) |
| 239 |
{ |
| 240 |
return formatData(QString::number(data)); |
| 241 |
} |
| 242 |
|
| 243 |
/** |
| 244 |
* This is an overload, provided for convenience. |
| 245 |
*/ |
| 246 |
static inline QString formatData(const char *const data) |
| 247 |
{ |
| 248 |
return formatData(QLatin1String(data)); |
| 249 |
} |
| 250 |
|
| 251 |
/** |
| 252 |
* This is an overload, provided for convenience. |
| 253 |
*/ |
| 254 |
static inline QString formatData(const QLatin1Char &data) |
| 255 |
{ |
| 256 |
return formatData(QString(data)); |
| 257 |
} |
| 258 |
|
| 259 |
/** |
| 260 |
* Formats an arbitrary expression, such as a regular expression |
| 261 |
* or XQuery query. |
| 262 |
*/ |
| 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 |
|
| 280 |
QT_END_NAMESPACE |
| 281 |
#endif |