@Override public GroundedValue<T> getResidue() { if (start == 0 && pos == 0) { return baseValue; } else { return baseValue.subsequence(start + pos, Integer.MAX_VALUE); } }
public T next() throws XPathException { return baseValue.itemAt(start + pos++); }
if (val0.getLength() != val1.getLength()) { return false; if (val0.getLength() == 1) { Item i0 = val0.head(); Item i1 = val1.head(); if (i0 instanceof AtomicValue) { return i1 instanceof AtomicValue && ((AtomicValue) i0).isIdentical((AtomicValue) i1); for (int i = 0; i < val0.getLength(); i++) { if (!valuesAreCompatible(val0.itemAt(i), val1.itemAt(i))) { return false;
/** * Produce a short string identifying the expression for use in error messages * * @return a short string, sufficient to identify the expression */ @Override public String toShortString() { if (value.getLength() == 0) { return "()"; } else if (value instanceof AtomicValue) { return value.toString(); } else { return "(" + value.head() + ",...)"; } }
/** * Used to detect warning condition when braces are undoubled in the regex attribute of xsl:analyze-string * * @param exp an expression * @return true if the expression is an integer literal or a pair of two integer literals */ private static boolean isIntegerOrIntegerPair(Expression exp) { if (exp instanceof Literal) { GroundedValue val = ((Literal) exp).getValue(); if (val instanceof IntegerValue) { return true; } if (val.getLength() == 2) { return val.itemAt(0) instanceof IntegerValue && val.itemAt(1) instanceof IntegerValue; } } return false; }
/** * Static factory method. Creates a SubsequenceIterator, unless for example the base Iterator is an * ArrayIterator, in which case it optimizes by creating a new ArrayIterator directly over the * underlying array. This optimization is important when doing recursion over a node-set using * repeated calls of <code>$nodes[position()>1]</code> * * @param base An iteration of the items to be filtered * @param min The position of the first item to be included (base 1) * @param max The position of the last item to be included (base 1) * @return an iterator over the requested subsequence * @throws XPathException if a dynamic error occurs */ public static <T extends Item<?>> SequenceIterator<T> make(SequenceIterator<T> base, int min, int max) throws XPathException { if (base instanceof ArrayIterator) { return ((ArrayIterator<T>) base).makeSliceIterator(min, max); } else if (max == Integer.MAX_VALUE) { return TailIterator.make(base, min); } else if ((base.getProperties() & SequenceIterator.GROUNDED) != 0 && min > 4) { GroundedValue<T> value = base.materialize(); value = value.subsequence(min - 1, max - min + 1); return value.iterate(); } else { return new SubsequenceIterator<>(base, min, max); } }
private void tryToBindRegularExpression(Expression[] arguments) { // For all these functions, the regular expression is the second argument, and the flags // argument is the last argument. if (arguments[1] instanceof Literal && arguments[arguments.length - 1] instanceof Literal) { try { Configuration config = getRetainedStaticContext().getConfiguration(); String re = ((Literal) arguments[1]).getValue().getStringValue(); String flags = ((Literal) arguments[arguments.length - 1]).getValue().getStringValue(); String hostLang = "XP30"; if (config.getXsdVersion() == Configuration.XSD11) { hostLang += "/XSD11"; } List<String> warnings = new ArrayList<>(1); staticRegex = config.compileRegularExpression(re, flags, hostLang, warnings); if (!allowRegexMatchingEmptyString() && staticRegex.matches("")) { staticRegex = null; // will cause a dynamic error } } catch (XPathException err) { // If the regex is invalid, we leave it to be evaluated again at execution time } } }
/** * Return an Iterator to iterate over the values of a sequence. The value of every * expression can be regarded as a sequence, so this method is supported for all * expressions. This default implementation handles iteration for expressions that * return singleton values: for non-singleton expressions, the subclass must * provide its own implementation. * * @return a SequenceIterator that can be used to iterate over the result * of the expression * @throws net.sf.saxon.trans.XPathException if any dynamic error occurs evaluating the * expression */ /*@NotNull*/ public SequenceIterator iterate() throws XPathException { return value.iterate(); }
/** * Determine whether this is a vacuous expression as defined in the XQuery update specification * * @return true if this expression is vacuous */ public boolean isVacuousExpression() { return value.getLength() == 0; }
public static CharSequence depictSequence(Sequence<?> seq) { try { GroundedValue<?> val = seq.materialize(); if (val.getLength() == 0) { return "()"; } else if (val.getLength() == 1) { return depict(seq.head()); } else { return depictSequenceStart(val.iterate(), 3, val.getLength()); } } catch (XPathException e) { return "(*unreadable*)"; } }
SequenceIterator iter = val.iterate(); Item next; while ((next = iter.next()) != null) { val = val.materialize();
/** * Evaluate as a singleton item (or empty sequence). Note: this implementation returns * the first item in the sequence. The method should not be used unless appropriate type-checking * has been done to ensure that the value will be a singleton. */ public Item evaluateItem(XPathContext context) throws XPathException { return value.head(); }
/** * Get the effective boolean value of the expression. This returns false if the value * is the empty sequence, a zero-length string, a number equal to zero, or the boolean * false. Otherwise it returns true. * * @param context The context in which the expression is to be evaluated * @return the effective boolean value * @throws net.sf.saxon.trans.XPathException if any dynamic error occurs evaluating the * expression */ public boolean effectiveBooleanValue(XPathContext context) throws XPathException { return value.effectiveBooleanValue(); }
maybeCombined = false; } else if (args[1] instanceof Literal) { MapItem options = (MapItem) ((Literal) args[1]).getValue().head(); GroundedValue dupes = options.get(new StringValue("duplicates")); try { if (!"combine".equals(dupes.getStringValue())) { maybeCombined = false;
/** * Get the contents of this value in the form of a Java {@link java.lang.Iterable}, * so that it can be used in a for-each expression. In the general case, obtaining * the iterable may raise dynamic errors; but the {@link java.util.Iterator} obtained * from the iterable will be error-free. Subclasses of {@link Sequence} that * implement {@link GroundedValue} are directly iterable, so this method is a no-op * in those cases. * * @return an Iterable containing the same sequence of items */ default Iterable<T> asIterable() throws XPathException { return iterate().materialize().asIterable(); }
/** * Write an item into the current map, with the preselected key * @param val the value/map to be written */ private void writeItem(GroundedValue<?> val) { if (stack.empty()) { stack.push(val); } else if (stack.peek() instanceof ArrayItem) { SimpleArrayItem array = (SimpleArrayItem) stack.peek(); array.getMembers().add(val.materialize()); } else { DictionaryMap map = (DictionaryMap) stack.peek(); //StringValue key = new StringValue(reEscape(keys.pop(), true, false, false)); //StringValue key = new StringValue(keys.pop()); map.initialPut(keys.pop(), val); } }
CharSequence value = ((Literal) getSelect()).getValue().getStringValueCS(); ValidationFailure err = schemaType.validateContent( value, DummyNamespaceResolver.getInstance(), rules);
/** * Produce a short string identifying the expression for use in error messages * * @return a short string, sufficient to identify the expression */ @Override public String toShortString() { if (value.getLength() == 0) { return "()"; } else if (value instanceof AtomicValue) { return value.toString(); } else { return "(" + value.head() + ",...)"; } }
/** * Static factory method. Creates a SubsequenceIterator, unless for example the base Iterator is an * ArrayIterator, in which case it optimizes by creating a new ArrayIterator directly over the * underlying array. This optimization is important when doing recursion over a node-set using * repeated calls of <code>$nodes[position()>1]</code> * * @param base An iteration of the items to be filtered * @param min The position of the first item to be included (base 1) * @param max The position of the last item to be included (base 1) * @return an iterator over the requested subsequence * @throws XPathException if a dynamic error occurs */ public static <T extends Item<?>> SequenceIterator<T> make(SequenceIterator<T> base, int min, int max) throws XPathException { if (base instanceof ArrayIterator) { return ((ArrayIterator<T>) base).makeSliceIterator(min, max); } else if (max == Integer.MAX_VALUE) { return TailIterator.make(base, min); } else if ((base.getProperties() & SequenceIterator.GROUNDED) != 0 && min > 4) { GroundedValue<T> value = base.materialize(); value = value.subsequence(min - 1, max - min + 1); return value.iterate(); } else { return new SubsequenceIterator<>(base, min, max); } }
@Override public Expression makeOptimizedFunctionCall(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo, Expression... arguments) throws XPathException { boolean opt = true; if (!(arguments[1] instanceof Literal)) { opt = false; } if (arguments.length == 3 && !(arguments[2] instanceof Literal)) { opt = false; } if (!opt) { return super.makeOptimizedFunctionCall(visitor, contextInfo, arguments); } Configuration config = visitor.getConfiguration(); String language = arguments.length == 3 ? ((Literal)arguments[2]).getValue().getStringValue() : config.getDefaultLanguage(); Numberer numb = config.makeNumberer(language, null); formatter = makeFormatter(numb, ((Literal)arguments[1]).getValue().getStringValue()); return super.makeOptimizedFunctionCall(visitor, contextInfo, arguments); }