Qt 4.8
qsubstringfns.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 "qboolean_p.h"
43 #include "qcommonvalues_p.h"
44 #include "qliteral_p.h"
45 #include "qatomicstring_p.h"
46 
47 #include "qsubstringfns_p.h"
48 
50 
51 using namespace QPatternist;
52 
54 {
55  const Item op1(m_operands.first()->evaluateSingleton(context));
56  QString str1;
57 
58  if(op1)
59  str1 = op1.stringValue();
60 
61  const Item op2(m_operands.at(1)->evaluateSingleton(context));
62  QString str2;
63 
64  if(op2)
65  str2 = op2.stringValue();
66 
67  if(str2.isEmpty())
69 
70  if(str1.isEmpty())
72 
73  return Boolean::fromValue(str1.contains(str2, caseSensitivity()));
74 }
75 
77 {
78  const Item op1(m_operands.first()->evaluateSingleton(context));
79  QString str1;
80 
81  if(op1)
82  str1 = op1.stringValue();
83 
84  const Item op2(m_operands.at(1)->evaluateSingleton(context));
85  QString str2;
86 
87  if(op2)
88  str2 = op2.stringValue();
89 
90  if(str2.isEmpty())
92 
93  if(str1.isEmpty())
95 
96  return Boolean::fromValue(str1.startsWith(str2, caseSensitivity()));
97 }
98 
100 {
101  const Item op1(m_operands.first()->evaluateSingleton(context));
102  QString str1;
103 
104  if(op1)
105  str1 = op1.stringValue();
106 
107  const Item op2(m_operands.at(1)->evaluateSingleton(context));
108  QString str2;
109 
110  if(op2)
111  str2 = op2.stringValue();
112 
113  if(str2.isEmpty())
115 
116  if(str1.isEmpty())
118 
119  return Boolean::fromValue(str1.endsWith(str2, caseSensitivity()));
120 }
121 
123 {
124  const Item op1(m_operands.first()->evaluateSingleton(context));
125  QString str1;
126 
127  if(op1)
128  str1 = op1.stringValue();
129 
130  const Item op2(m_operands.at(1)->evaluateSingleton(context));
131  QString str2;
132 
133  if(op2)
134  str2 = op2.stringValue();
135 
136  const int pos = str1.indexOf(str2);
137  if(pos == -1)
139 
140  return AtomicString::fromValue(QString(str1.left(pos)));
141 }
142 
144 {
145  const Item op1(m_operands.first()->evaluateSingleton(context));
146  QString str1;
147 
148  if(op1)
149  str1 = op1.stringValue();
150 
151  const Item op2(m_operands.at(1)->evaluateSingleton(context));
152  QString str2;
153 
154  if(op2)
155  str2 = op2.stringValue();
156 
157  if(str2.isEmpty())
158  {
159  if(op1)
160  return op1;
161  else
163  }
164 
165  const int pos = str1.indexOf(str2);
166 
167  if(pos == -1)
169 
170  return AtomicString::fromValue(QString(str1.right(str1.length() - (pos + str2.length()))));
171 }
172 
virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
static const AtomicValue::Ptr BooleanTrue
The QString class provides a Unicode character string.
Definition: qstring.h:83
static AtomicString::Ptr fromValue(const QString &value)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The namespace for the internal API of QtXmlPatterns.
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const
static Boolean::Ptr fromValue(const bool value)
Definition: qboolean.cpp:115
virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const
virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
static const AtomicValue::Ptr EmptyString
Contains classes implementing the functions found in XQuery 1.0 and XPath 2.0 Functions and Operators...
Qt::CaseSensitivity caseSensitivity() const
static const AtomicValue::Ptr BooleanFalse
virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const