1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "qboolean_p.h"
43 #include "qcommonvalues_p.h"
44 #include "qliteral_p.h"
45 #include "qatomicstring_p.h"
47 #include "qsubstringfns_p.h"
51 using namespace QPatternist;
53 Item ContainsFN::evaluateSingleton(const DynamicContext::Ptr &context) const
55 const Item op1(m_operands.first()->evaluateSingleton(context));
59 str1 = op1.stringValue();
61 const Item op2(m_operands.at(1)->evaluateSingleton(context));
65 str2 = op2.stringValue();
68 return CommonValues::BooleanTrue;
71 return CommonValues::BooleanFalse;
73 return Boolean::fromValue(str1.contains(str2, caseSensitivity()));
76 Item StartsWithFN::evaluateSingleton(const DynamicContext::Ptr &context) const
78 const Item op1(m_operands.first()->evaluateSingleton(context));
82 str1 = op1.stringValue();
84 const Item op2(m_operands.at(1)->evaluateSingleton(context));
88 str2 = op2.stringValue();
91 return CommonValues::BooleanTrue;
94 return CommonValues::BooleanFalse;
96 return Boolean::fromValue(str1.startsWith(str2, caseSensitivity()));
99 Item EndsWithFN::evaluateSingleton(const DynamicContext::Ptr &context) const
101 const Item op1(m_operands.first()->evaluateSingleton(context));
105 str1 = op1.stringValue();
107 const Item op2(m_operands.at(1)->evaluateSingleton(context));
111 str2 = op2.stringValue();
114 return CommonValues::BooleanTrue;
117 return CommonValues::BooleanFalse;
119 return Boolean::fromValue(str1.endsWith(str2, caseSensitivity()));
122 Item SubstringBeforeFN::evaluateSingleton(const DynamicContext::Ptr &context) const
124 const Item op1(m_operands.first()->evaluateSingleton(context));
128 str1 = op1.stringValue();
130 const Item op2(m_operands.at(1)->evaluateSingleton(context));
134 str2 = op2.stringValue();
136 const int pos = str1.indexOf(str2);
138 return CommonValues::EmptyString;
140 return AtomicString::fromValue(QString(str1.left(pos)));
143 Item SubstringAfterFN::evaluateSingleton(const DynamicContext::Ptr &context) const
145 const Item op1(m_operands.first()->evaluateSingleton(context));
149 str1 = op1.stringValue();
151 const Item op2(m_operands.at(1)->evaluateSingleton(context));
155 str2 = op2.stringValue();
162 return CommonValues::EmptyString;
165 const int pos = str1.indexOf(str2);
168 return CommonValues::EmptyString;
170 return AtomicString::fromValue(QString(str1.right(str1.length() - (pos + str2.length()))));