Qt 4.8
qprocessinginstructionconstructor.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 "qcommonsequencetypes_p.h"
43 #include "qpatternistlocale_p.h"
44 #include "qnodebuilder_p.h"
45 #include "qqnamevalue_p.h"
46 
48 
50 
51 using namespace QPatternist;
52 
55  const Expression::Ptr &op2) : PairContainer(op1, op2)
56 {
57 }
58 
60 {
61  const int len = input.length();
62 
63  for(int i = 0; i < len; ++i)
64  {
65  if(!input.at(i).isSpace())
66  return input.mid(i);
67  }
68 
69  return QString(); /* input consists only of whitespace. All was trimmed. */
70 }
71 
73 {
74  const Item name(m_operand1->evaluateSingleton(context));
75  const Item dataArg(m_operand2->evaluateSingleton(context));
76 
77  if(dataArg)
78  {
79  /* Perform trimming before validation, to increase speed. */
80  const QString value(leftTrimmed(dataArg.stringValue()));
81 
82  if(value.contains(QLatin1String("?>")))
83  {
84  context->error(QtXmlPatterns::tr("The data of a processing instruction cannot contain the string %1").arg(formatData("?>")),
86  return QString();
87  }
88  else
89  return value;
90  }
91  else
92  return QString();
93 }
94 
96 {
97  const Item name(m_operand1->evaluateSingleton(context));
98  return context->namePool()->allocateQName(QString(), name.stringValue());
99 }
100 
102 {
103  const NodeBuilder::Ptr nodeBuilder(context->nodeBuilder(QUrl()));
104 
105  nodeBuilder->processingInstruction(evaluateTardata(context), data(context));
106 
107  const QAbstractXmlNodeModel::Ptr nm(nodeBuilder->builtDocument());
108  context->addNodeModel(nm);
109 
110  return nm->root(QXmlNodeModelIndex());
111 }
112 
114 {
115  QAbstractXmlReceiver *const receiver = context->outputReceiver();
116 
117  receiver->processingInstruction(evaluateTardata(context), data(context));
118 }
119 
121 {
123 }
124 
126 {
127  SequenceType::List result;
130  return result;
131 }
132 
134 {
136 }
137 
140 {
141  return visitor->visit(this);
142 }
143 
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
QXmlName evaluateTardata(const DynamicContext::Ptr &context) const
virtual NamePool::Ptr namePool() const =0
The QXmlNodeModelIndex class identifies a node in an XML node model subclassed from QAbstractXmlNodeM...
virtual void addNodeModel(const QAbstractXmlNodeModel::Ptr &nm)=0
A push interface for the XPath Data Model. Similar to SAX&#39;s ContentHandler.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
static const SequenceType::Ptr ExactlyOneString
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
bool isSpace() const
Returns true if the character is a separator character (Separator_* categories); otherwise returns fa...
Definition: qchar.cpp:609
static const SequenceType::Ptr ZeroOrOneString
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
virtual void evaluateToSequenceReceiver(const DynamicContext::Ptr &context) const
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void error(const QString &message, const ReportContext::ErrorCode errorCode, const QSourceLocation &sourceLocation)
const char * name
The namespace for the internal API of QtXmlPatterns.
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
virtual void processingInstruction(const QXmlName name, const QString &value)=0
static QString formatData(const QString &data)
QString data(const DynamicContext::Ptr &context) const
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
The QXmlName class represents the name of an XML node, in an efficient, namespace-aware way...
Definition: qxmlname.h:58
static const SequenceType::Ptr ExactlyOneProcessingInstruction
Contains functions used for formatting arguments, such as keywords and paths, in translated strings...
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
QXmlName allocateQName(const QString &uri, const QString &localName, const QString &prefix=QString())
Definition: qnamepool.cpp:251
virtual ExpressionVisitorResult::Ptr accept(const ExpressionVisitor::Ptr &visitor) const
virtual NodeBuilder::Ptr nodeBuilder(const QUrl &baseURI) const =0
The QFlags class provides a type-safe way of storing OR-combinations of enum values.
Definition: qglobal.h:2313
virtual QAbstractXmlReceiver * outputReceiver() const =0
ProcessingInstructionConstructor(const Expression::Ptr &operand1, const Expression::Ptr &operand2)
virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const
virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
Base class for expressions that has exactly two operands.