Qt 4.8
qxpath10corefunctions.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 "qbuiltintypes_p.h"
43 #include "qcommonnamespaces_p.h"
44 #include "qcommonsequencetypes_p.h"
45 #include "qcommonvalues_p.h"
46 #include "qpatternistlocale_p.h"
47 #include "qxmlname.h"
48 
49 /* Functions */
50 #include "qaccessorfns_p.h"
51 #include "qaggregatefns_p.h"
52 #include "qbooleanfns_p.h"
53 #include "qcomparestringfns_p.h"
54 #include "qcontextfns_p.h"
55 #include "qnodefns_p.h"
56 #include "qnumericfns_p.h"
57 #include "qsequencefns_p.h"
59 #include "qstringvaluefns_p.h"
60 #include "qsubstringfns_p.h"
61 
63 
65 
66 using namespace QPatternist;
67 
69  const Expression::List &args,
70  const FunctionSignature::Ptr &sign) const
71 {
72  Q_ASSERT(sign);
73 
74  Expression::Ptr fn;
75 #define testFN(ln, cname) else if(name.localName() == StandardLocalNames::ln) fn = Expression::Ptr(new cname())
76 
77  if(false) /* Dummy for the macro handling. Will be optimized away anyway. */
78  return Expression::Ptr();
79  /* Alphabetic order. */
80  testFN(boolean, BooleanFN);
81  testFN(ceiling, CeilingFN);
82  testFN(concat, ConcatFN);
83  testFN(contains, ContainsFN);
84  testFN(count, CountFN);
85  testFN(False, FalseFN);
86  testFN(floor, FloorFN);
87  testFN(id, IdFN);
88  testFN(lang, LangFN);
89  testFN(last, LastFN);
90  testFN(local_name, LocalNameFN);
91  testFN(name, NameFN);
92  testFN(namespace_uri, NamespaceURIFN);
93  testFN(normalize_space, NormalizeSpaceFN);
94  testFN(Not, NotFN);
95  testFN(number, NumberFN);
97  testFN(round, RoundFN);
98  testFN(starts_with, StartsWithFN);
99  testFN(string, StringFN);
100  testFN(string_length, StringLengthFN);
101  testFN(substring, SubstringFN);
102  testFN(substring_after, SubstringAfterFN);
103  testFN(substring_before, SubstringBeforeFN);
104  testFN(sum, SumFN);
105  testFN(translate, TranslateFN);
106  testFN(True, TrueFN);
107 #undef testFN
108 
109  Q_ASSERT(fn);
110  fn->setOperands(args);
111  fn->as<FunctionCall>()->setSignature(sign);
112 
113  return fn;
114 }
115 
117 {
119  return FunctionSignature::Ptr();
120 
122 
123  if(!s)
124  {
125  const QXmlName::LocalNameCode localName(name.localName());
126 
127  /* Alphabetic order. */
128  if(StandardLocalNames::boolean == localName)
129  {
132  }
133  else if(StandardLocalNames::ceiling == localName)
134  {
138  }
139  else if(StandardLocalNames::concat == localName)
140  {
145  }
146  else if(StandardLocalNames::contains == localName)
147  {
153  }
154  else if(StandardLocalNames::count == localName)
155  {
158  }
159  else if(StandardLocalNames::False == localName)
160  {
162  }
163  else if(StandardLocalNames::floor == localName)
164  {
168  }
169  else if(StandardLocalNames::id == localName)
170  {
175  }
176  else if(StandardLocalNames::lang == localName)
177  {
182  }
183  else if(StandardLocalNames::last == localName)
184  {
187  }
188  else if(StandardLocalNames::local_name == localName)
189  {
193  }
194  else if(StandardLocalNames::name == localName)
195  {
199  }
200  else if(StandardLocalNames::namespace_uri == localName)
201  {
205  }
206  else if(StandardLocalNames::normalize_space == localName)
207  {
211  }
212  else if(StandardLocalNames::Not == localName)
213  {
216  }
217  else if(StandardLocalNames::number == localName)
218  {
222  }
223  else if(StandardLocalNames::position == localName)
224  {
227  }
228  else if(StandardLocalNames::round == localName)
229  {
233  }
234  else if(StandardLocalNames::starts_with == localName)
235  {
241  }
242  else if(StandardLocalNames::string == localName)
243  {
247  }
248  else if(StandardLocalNames::string_length == localName)
249  {
254  }
255  else if(StandardLocalNames::substring == localName)
256  {
261  }
262  else if(StandardLocalNames::substring_after == localName)
263  {
269  }
270  else if(StandardLocalNames::substring_before == localName)
271  {
277  }
278  else if(StandardLocalNames::sum == localName)
279  {
283  }
284  else if(StandardLocalNames::translate == localName)
285  {
290  }
291  else if(StandardLocalNames::True == localName)
292  {
294  }
295  }
296 
297  return s;
298 }
299 
Base class for implementations of builtin functions.
Contains classes implementing the functions found in XQuery 1.0 and XPath 2.0 Functions and Operators...
Contains classes implementing the functions found in XQuery 1.0 and XPath 2.0 Functions and Operators...
static const SequenceType::Ptr ZeroOrOneNode
virtual void setOperands(const Expression::List &operands)=0
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
NamespaceCode LocalNameCode
Definition: qxmlname.h:84
Implements the function fn:concat().
Implements the function fn:string().
Implements the function fn:number().
Definition: qnodefns_p.h:117
static const SequenceType::Ptr ZeroOrMoreItems
#define testFN(ln, cname)
static QXmlName::LocalNameCode argument(const NamePool::Ptr &np, const char *const name)
Contains classes implementing the functions found in XQuery 1.0 and XPath 2.0 Functions and Operators...
Implements the function fn:name().
Definition: qnodefns_p.h:79
void appendArgument(const QXmlName::LocalNameCode name, const SequenceType::Ptr &type)
Implements the function fn:sum().
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
static const SequenceType::Ptr ExactlyOneString
Implements the function fn:last().
Definition: qcontextfns_p.h:94
Implements the function fn:ceiling().
Implements the function fn:normalize-space().
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
FunctionSignature::Ptr addFunction(const QXmlName::LocalNameCode localName, const FunctionSignature::Arity minArgs, const FunctionSignature::Arity maxArgs, const SequenceType::Ptr &returnType, const Expression::Properties props)
Implements the function fn:lang().
Definition: qnodefns_p.h:146
static const SequenceType::Ptr ZeroOrOneString
static int sign(int x)
Implements the function fn:starts-with().
static const SequenceType::Ptr ExactlyOneInteger
Implements the function fn:local-name().
Definition: qnodefns_p.h:91
virtual FunctionSignature::Hash functionSignatures() const
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
const TCastTarget * as() const
static const SequenceType::Ptr ExactlyOneAnyURI
Implements the function fn:false().
Definition: qbooleanfns_p.h:95
static const SequenceType::Ptr ZeroOrMoreElements
Contains classes implementing the functions found in XQuery 1.0 and XPath 2.0 Functions and Operators...
Implements the function fn:substring-before().
const char * name
Implements the function fn:substring().
The namespace for the internal API of QtXmlPatterns.
Implements the function fn:namespace-uri().
Definition: qnodefns_p.h:103
Implements the function fn:round().
Contains classes implementing the functions found in XQuery 1.0 and XPath 2.0 Functions and Operators...
Contains classes implementing the functions found in XQuery 1.0 and XPath 2.0 Functions and Operators...
Implements the function fn:true().
Definition: qbooleanfns_p.h:81
Contains classes implementing the functions found in XQuery 1.0 and XPath 2.0 Functions and Operators...
QString localName(const QXmlNamePool &query) const
Returns the local name.
Definition: qxmlname.cpp:387
static const SequenceType::Ptr ZeroOrOneNumeric
QExplicitlySharedDataPointer< Expression > Ptr
A smart pointer wrapping mutable Expression instances.
static const SequenceType::Ptr ExactlyOneBoolean
NamespaceCode namespaceURI() const
Definition: qnamepool_p.h:503
The QXmlName class represents the name of an XML node, in an efficient, namespace-aware way...
Definition: qxmlname.h:58
static const SequenceType::Ptr ExactlyOneDouble
Contains functions used for formatting arguments, such as keywords and paths, in translated strings...
Contains classes implementing the functions found in XQuery 1.0 and XPath 2.0 Functions and Operators...
static const SequenceType::Ptr EBV
Implements the function fn:string-length().
Implements the function fn:count().
Implements the function fn:contains().
Implements the function fn:id().
virtual Expression::Ptr retrieveExpression(const QXmlName name, const Expression::List &args, const FunctionSignature::Ptr &sign) const
Implements the function fn:floor().
Definition: qnumericfns_p.h:79
static const SequenceType::Ptr ZeroOrOneAtomicType
static const SequenceType::Ptr ZeroOrMoreAtomicTypes
Contains classes implementing the functions found in XQuery 1.0 and XPath 2.0 Functions and Operators...
Implements the function fn:substring-after().
Implements the function fn:position().
Definition: qcontextfns_p.h:80
Implements the function fn:boolean().
static const SequenceType::Ptr ZeroOrOneItem
virtual FunctionSignature::Ptr retrieveFunctionSignature(const NamePool::Ptr &np, const QXmlName name)
Implements the function fn:not().
Contains classes implementing the functions found in XQuery 1.0 and XPath 2.0 Functions and Operators...
static const SequenceType::Ptr ZeroOrMoreStrings
Implements the function fn:translate().
static const SequenceType::Ptr ExactlyOneNode
Contains classes implementing the functions found in XQuery 1.0 and XPath 2.0 Functions and Operators...