Qt 4.8
Static Public Functions | Private Functions | List of all members
QPatternist::XPathHelper Class Reference

Contains helper and utility functions. More...

#include <qxpathhelper_p.h>

Static Public Functions

template<const ReportContext::ErrorCode code, typename TReportContext >
static void checkCollationSupport (const QString &collation, const TReportContext &context, const SourceLocationReflection *const r)
 
static bool isQName (const QString &qName)
 
static bool isReservedNamespace (const QXmlName::NamespaceCode ns)
 
static bool isWhitespaceOnly (const QStringRef &string)
 Determines whether consists only of whitespace. Characters considered whitespace are the ones for which QChar::isSpace() returns true for. More...
 
static bool isWhitespaceOnly (const QString &string)
 
static QUrl normalizeQueryURI (const QUrl &uri)
 
static void splitQName (const QString &qName, QString &prefix, QString &localName)
 Splits qName into localName and prefix. More...
 
static QPatternist::ItemTypePtr typeFromKind (const QXmlNodeModelIndex::NodeKind nodeKind)
 

Private Functions

 XPathHelper ()
 This default constructor has no definition, in order to avoid instantiation, since it makes no sense to instantiate this class. More...
 

Detailed Description

Contains helper and utility functions.

The common denominator of its functions is that they do not fit in well elsewhere, such as in a particular class. It is preferred if XPathHelper goes away, and that functions are in more specific classes.

Author
Frans Englich frans.nosp@m..eng.nosp@m.lich@.nosp@m.noki.nosp@m.a.com

Definition at line 76 of file qxpathhelper_p.h.

Constructors and Destructors

◆ XPathHelper()

QPatternist::XPathHelper::XPathHelper ( )
inlineprivate

This default constructor has no definition, in order to avoid instantiation, since it makes no sense to instantiate this class.

Referenced by isWhitespaceOnly().

Functions

◆ checkCollationSupport()

template<const ReportContext::ErrorCode code, typename TReportContext >
static void QPatternist::XPathHelper::checkCollationSupport ( const QString collation,
const TReportContext &  context,
const SourceLocationReflection *const  r 
)
inlinestatic

Determines whether collation is a supported string collation. If it is not, error code code is raised via context.

Definition at line 111 of file qxpathhelper_p.h.

114  {
115  Q_ASSERT(context);
116  Q_ASSERT(r);
117 
119  {
120  context->error(QtXmlPatterns::tr("Only the Unicode Codepoint "
121  "Collation is supported(%1). %2 is unsupported.")
123  .arg(formatURI(collation)),
124  code, r);
125  }
126  }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
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

◆ isQName()

bool XPathHelper::isQName ( const QString qName)
static

Determines whether qName is a valid QName. For example, "body" and "xhtml:body" is, but "xhtml::body" or "x:body "(note the whitespace) is not.

See also
QNameConstructor::expandQName()
QNameValue

Definition at line 64 of file qxpathhelper.cpp.

Referenced by QPatternist::XsdTypeChecker::checkConstrainingFacetsQName(), QPatternist::QNameFN::evaluateSingleton(), QPatternist::QNameConstructor::expandQName(), QPatternist::NamePool::fromClarkName(), QPatternist::XsdTypeChecker::isValidString(), QPatternist::XsdSchemaParser::parseGlobalElement(), QPatternist::XsdValidatingInstanceReader::qNameAttribute(), QPatternist::XsdSchemaParser::readQNameAttribute(), QPatternist::XsdSchemaResolver::resolveEnumerationFacetValues(), and splitQName().

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 }
unsigned char c[8]
Definition: qnumeric_p.h:62
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
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 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

◆ isReservedNamespace()

bool XPathHelper::isReservedNamespace ( const QXmlName::NamespaceCode  ns)
static

Determines whether ns is a reserved namespace.

See also
XSL Transformations (XSLT) Version 2.0, 3.2 Reserved Namespaces
XQuery 1.0: An XML Query Language, 4.15 Function Declaration
Returns
true if ns is a reserved namespace, otherwise false.

Definition at line 55 of file qxpathhelper.cpp.

Referenced by QPatternist::yyparse().

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 }

◆ isWhitespaceOnly() [1/2]

static bool QPatternist::XPathHelper::isWhitespaceOnly ( const QStringRef string)
inlinestatic

Determines whether consists only of whitespace. Characters considered whitespace are the ones for which QChar::isSpace() returns true for.

For the empty string, true is returned.

Returns
true if string consists only of whitespace, otherwise false.

Definition at line 143 of file qxpathhelper_p.h.

Referenced by isWhitespaceOnly(), QXmlFormatter::item(), QXmlFormatter::startFormattingContent(), and QPatternist::yyparse().

144  {
145  const int len = string.length();
146 
147  for(int i = 0; i < len; ++i)
148  {
149  if(!string.at(i).isSpace()) // TODO and this is wrong, see sdk/TODO
150  return false;
151  }
152 
153  return true;
154  }
#define at(className, varName)

◆ isWhitespaceOnly() [2/2]

static bool QPatternist::XPathHelper::isWhitespaceOnly ( const QString string)
inlinestatic

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 159 of file qxpathhelper_p.h.

160  {
161  return isWhitespaceOnly(QStringRef(&string));
162  }
The QStringRef class provides a thin wrapper around QString substrings.
Definition: qstring.h:1099
static bool isWhitespaceOnly(const QStringRef &string)
Determines whether consists only of whitespace. Characters considered whitespace are the ones for whi...

◆ normalizeQueryURI()

QUrl XPathHelper::normalizeQueryURI ( const QUrl uri)
static

Normalizes an uri by resolving it to the application directory if empty.

Definition at line 128 of file qxpathhelper.cpp.

Referenced by checkCollationSupport(), QXmlSchemaPrivate::load(), QXmlQuery::setQuery(), and QXmlSchemaValidator::validate().

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 }
bool isValid() const
Returns true if the URL is valid; otherwise returns false.
Definition: qurl.cpp:4303
static QString applicationFilePath()
Returns the file path of the application executable.
bool isEmpty() const
Returns true if the URL has no data; otherwise returns false.
Definition: qurl.cpp:4317
bool isRelative() const
Returns true if the URL is relative; otherwise returns false.
Definition: qurl.cpp:5880
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
static QUrl fromLocalFile(const QString &localfile)
Returns a QUrl representation of localFile, interpreted as a local file.
Definition: qurl.cpp:6374
#define Q_FUNC_INFO
Definition: qglobal.h:1871

◆ splitQName()

void XPathHelper::splitQName ( const QString qName,
QString prefix,
QString localName 
)
static

Splits qName into localName and prefix.

Note
qName must be a valid QName, and that is not checked.

Definition at line 80 of file qxpathhelper.cpp.

Referenced by QPatternist::ElementAvailableFN::evaluateEBV(), QPatternist::QNameFN::evaluateSingleton(), QPatternist::QNameConstructor::expandQName(), QPatternist::NamePool::fromClarkName(), and QPatternist::yyparse().

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 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
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 bool isQName(const QString &qName)
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
#define Q_FUNC_INFO
Definition: qglobal.h:1871

◆ typeFromKind()

ItemType::Ptr XPathHelper::typeFromKind ( const QXmlNodeModelIndex::NodeKind  nodeKind)
static

Definition at line 103 of file qxpathhelper.cpp.

Referenced by checkCollationSupport(), and QPatternist::AccelTree::type().

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 }
static const ItemType::Ptr document
QExplicitlySharedDataPointer< ItemType > Ptr
Definition: qitemtype_p.h:88
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
static const ItemType::Ptr attribute
static const ItemType::Ptr text
static const ItemType::Ptr pi
static const ItemType::Ptr element
static const ItemType::Ptr comment
#define Q_FUNC_INFO
Definition: qglobal.h:1871

The documentation for this class was generated from the following files: