All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.saxon.functions.CodepointEqual Maven / Gradle / Ivy

There is a newer version: 10.5
Show newest version
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2013 Saxonica Limited.
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

package net.sf.saxon.functions;

import net.sf.saxon.expr.Callable;
import net.sf.saxon.expr.XPathContext;
import net.sf.saxon.om.Sequence;
import net.sf.saxon.trans.XPathException;
import net.sf.saxon.value.BooleanValue;
import net.sf.saxon.value.EmptySequence;
import net.sf.saxon.value.StringValue;

/**
 * Implements the XPath 2.0 fn:codepoint-equal() function.
 *
 * 

Compares two strings using the unicode codepoint collation. (The function was introduced * specifically to allow URI comparison: URIs are promoted to strings when necessary.)

*/ public class CodepointEqual extends SystemFunctionCall implements Callable { /** * Evaluate the expression */ /*@Nullable*/ public BooleanValue evaluateItem(XPathContext context) throws XPathException { StringValue op1 = (StringValue)argument[0].evaluateItem(context); StringValue op2 = (StringValue)argument[1].evaluateItem(context); return codepointEqual(op1, op2); } public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException { StringValue op1 = (StringValue)arguments[0].head(); StringValue op2 = (StringValue)arguments[1].head(); BooleanValue b = codepointEqual(op1, op2); return (b == null ? EmptySequence.getInstance() : b); } private static BooleanValue codepointEqual(StringValue s1, StringValue s2) { if (s1 == null || s2 == null) { return null; } return BooleanValue.get(s1.getStringValue().equals(s2.getStringValue())); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy