Debian Codegraph @

net/sf/saxon/functions/Compare.java

raw symbols SCIP
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.XPathContext;
11 import net.sf.saxon.expr.sort.AtomicComparer;
12 import net.sf.saxon.expr.sort.GenericAtomicComparer;
13 import net.sf.saxon.om.Sequence;
14 import net.sf.saxon.om.ZeroOrOne;
15 import net.sf.saxon.trans.XPathException;
16 import net.sf.saxon.value.Int64Value;
17 import net.sf.saxon.value.StringValue;
18
19 /**
20 * This class implements the XPath 2.0 fn:compare() function
21 */
22
23 public class Compare extends CollatingFunctionFixed {
24
25 private static Int64Value compare(StringValue s1, StringValue s2, AtomicComparer comparer) throws XPathException {
26 if (s1 == null || s2 == null) {
27 return null;
28 }
29 int result = comparer.compareAtomicValues(s1, s2);
30 if (result < 0) {
31 return Int64Value.MINUS_ONE;
32 } else if (result > 0) {
33 return Int64Value.PLUS_ONE;
34 } else {
35 return Int64Value.ZERO;
36 }
37 }
38
39 public ZeroOrOne<Int64Value> call(XPathContext context, Sequence[] arguments) throws XPathException {
40 StringValue arg0 = (StringValue) arguments[0].head();
41 StringValue arg1 = (StringValue) arguments[1].head();
42 GenericAtomicComparer comparer = new GenericAtomicComparer(getStringCollator(), context);
43 Int64Value result = compare(arg0, arg1, comparer);
44 return new ZeroOrOne<>(result);
45 }
46
47 }
48