Qt 4.8
qxpathhelper.cpp
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 #include <QStringList>
43 
44 #include "private/qxmlutils_p.h"
45 #include "qbuiltintypes_p.h"
46 #include "qcommonvalues_p.h"
47 #include "qnamepool_p.h"
48 
49 #include "qxpathhelper_p.h"
50 
52 
53 using namespace QPatternist;
54 
56 {
57  /* The order is because of that XFN and WXS are the most common. */
58  return ns == StandardNamespaces::fn ||
59  ns == StandardNamespaces::xs ||
62 }
63 
64 bool XPathHelper::isQName(const QString &qName)
65 {
66  const QStringList result(qName.split(QLatin1Char(':')));
67  const int c = result.count();
68 
69  if(c == 2)
70  {
71  return QXmlUtils::isNCName(result.first()) &&
72  QXmlUtils::isNCName(result.last());
73  }
74  else if(c == 1)
75  return QXmlUtils::isNCName(result.first());
76  else
77  return false;
78 }
79 
80 void XPathHelper::splitQName(const QString &qName, QString &prefix, QString &ncName)
81 {
83  "qName must be a valid QName.");
84 
85  const QStringList result(qName.split(QLatin1Char(':')));
86 
87  if(result.count() == 1)
88  {
89  Q_ASSERT(QXmlUtils::isNCName(result.first()));
90  ncName = result.first();
91  }
92  else
93  {
94  Q_ASSERT(result.count() == 2);
95  Q_ASSERT(QXmlUtils::isNCName(result.first()));
96  Q_ASSERT(QXmlUtils::isNCName(result.last()));
97 
98  prefix = result.first();
99  ncName = result.last();
100  }
101 }
102 
104 {
105  switch(nodeKind)
106  {
108  return BuiltinTypes::element;
112  return BuiltinTypes::text;
114  return BuiltinTypes::pi;
116  return BuiltinTypes::comment;
118  return BuiltinTypes::document;
119  default:
120  {
121  Q_ASSERT_X(false, Q_FUNC_INFO,
122  "A node type that doesn't exist in the XPath Data Model was encountered.");
123  return ItemType::Ptr(); /* Dummy, silence compiler warning. */
124  }
125  }
126 }
127 
129 {
130  Q_ASSERT_X(uri.isEmpty() || uri.isValid(), Q_FUNC_INFO,
131  "The URI passed to QXmlQuery::setQuery() must be valid or empty.");
132  if(uri.isEmpty())
134  else if(uri.isRelative())
136  else
137  return uri;
138 }
139 
bool isValid() const
Returns true if the URL is valid; otherwise returns false.
Definition: qurl.cpp:4303
unsigned char c[8]
Definition: qnumeric_p.h:62
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
static QString applicationFilePath()
Returns the file path of the application executable.
qint16 NamespaceCode
Definition: qxmlname.h:82
bool isEmpty() const
Returns true if the URL has no data; otherwise returns false.
Definition: qurl.cpp:4317
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
static bool isReservedNamespace(const QXmlName::NamespaceCode ns)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isRelative() const
Returns true if the URL is relative; otherwise returns false.
Definition: qurl.cpp:5880
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
The namespace for the internal API of QtXmlPatterns.
static const ItemType::Ptr document
QExplicitlySharedDataPointer< ItemType > Ptr
Definition: qitemtype_p.h:88
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
NodeKind
Identifies a kind of node.
static const ItemType::Ptr attribute
static void splitQName(const QString &qName, QString &prefix, QString &localName)
Splits qName into localName and prefix.
static QUrl fromLocalFile(const QString &localfile)
Returns a QUrl representation of localFile, interpreted as a local file.
Definition: qurl.cpp:6374
static const ItemType::Ptr text
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
Definition: qstring.cpp:6526
static QPatternist::ItemTypePtr typeFromKind(const QXmlNodeModelIndex::NodeKind nodeKind)
static const ItemType::Ptr pi
static bool isQName(const QString &qName)
static const ItemType::Ptr element
static QUrl normalizeQueryURI(const QUrl &uri)
static bool isNCName(const QStringRef &ncName)
Determines whether c is a valid instance of production [4]NCName in the XML 1.0 Namespaces specificat...
Definition: qxmlutils.cpp:377
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
static const ItemType::Ptr comment
#define Q_FUNC_INFO
Definition: qglobal.h:1871