| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 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 |
|
| 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 |
|