| 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 2 | // Copyright (c) 2018 Saxonica Limited. |
| 3 | // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. |
| 4 | // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 5 | // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0. |
| 6 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 7 | |
| 8 | package net.sf.saxon.functions; |
| 9 | |
| 10 | import net.sf.saxon.expr.Expression; |
| 11 | import net.sf.saxon.expr.TailExpression; |
| 12 | import net.sf.saxon.expr.TailIterator; |
| 13 | import net.sf.saxon.expr.XPathContext; |
| 14 | import net.sf.saxon.om.Item; |
| 15 | import net.sf.saxon.om.Sequence; |
| 16 | import net.sf.saxon.om.SequenceIterator; |
| 17 | import net.sf.saxon.om.SequenceTool; |
| 18 | import net.sf.saxon.trans.XPathException; |
| 19 | |
| 20 | /** |
| 21 | * This class implements the function fn:tail(), which is a standard function in XPath 3.0 |
| 22 | */ |
| 23 | |
| 24 | public class TailFn extends SystemFunction { |
| 25 | |
| 26 | /** |
| 27 | * Evaluate the expression |
| 28 | * |
| 29 | * @param context the dynamic evaluation context |
| 30 | * @param arguments the values of the arguments, supplied as Sequences |
| 31 | * @return the result of the evaluation, in the form of a Sequence |
| 32 | * @throws net.sf.saxon.trans.XPathException |
| 33 | * if a dynamic error occurs during the evaluation of the expression |
| 34 | */ |
| 35 | public Sequence<?> call(XPathContext context, Sequence[] arguments) throws XPathException { |
| 36 | return SequenceTool.toLazySequence(TailIterator.make((SequenceIterator<Item<?>>)arguments[0].iterate(), 2)); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Convert static calls into a TailExpression |
| 41 | * @param arguments the supplied arguments to the call |
| 42 | * @return a TailExpression |
| 43 | */ |
| 44 | |
| 45 | @Override |
| 46 | public TailExpression makeFunctionCall(Expression[] arguments) { |
| 47 | return new TailExpression(arguments[0], 2); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | // Copyright (c) 2010-2015 Saxonica Limited. |