| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.functions; |
| 9 |
|
| 10 |
import net.sf.saxon.expr.Expression; |
| 11 |
import net.sf.saxon.expr.StaticProperty; |
| 12 |
import net.sf.saxon.expr.XPathContext; |
| 13 |
import net.sf.saxon.expr.instruct.SimpleNodeConstructor; |
| 14 |
import net.sf.saxon.expr.parser.ContextItemStaticInfo; |
| 15 |
import net.sf.saxon.expr.parser.ExpressionVisitor; |
| 16 |
import net.sf.saxon.om.Item; |
| 17 |
import net.sf.saxon.om.One; |
| 18 |
import net.sf.saxon.om.ZeroOrOne; |
| 19 |
import net.sf.saxon.trans.XPathException; |
| 20 |
import net.sf.saxon.type.BuiltInAtomicType; |
| 21 |
import net.sf.saxon.type.TypeHierarchy; |
| 22 |
import net.sf.saxon.value.AtomicValue; |
| 23 |
import net.sf.saxon.value.StringValue; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
public class String_1 extends ScalarSystemFunction { |
| 31 |
|
| 32 |
@Override |
| 33 |
public AtomicValue evaluate(Item arg, XPathContext context) throws XPathException { |
| 34 |
CharSequence result; |
| 35 |
try { |
| 36 |
result = arg.getStringValueCS(); |
| 37 |
} catch (UnsupportedOperationException err) { |
| 38 |
throw new XPathException(err.getMessage(), "FOTY0014"); |
| 39 |
} |
| 40 |
return new StringValue(result); |
| 41 |
} |
| 42 |
|
| 43 |
@Override |
| 44 |
public ZeroOrOne<? extends AtomicValue> resultWhenEmpty() { |
| 45 |
return new One<>(StringValue.EMPTY_STRING); |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
@Override |
| 59 |
public Expression makeOptimizedFunctionCall(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo, Expression... arguments) throws XPathException { |
| 60 |
TypeHierarchy th = visitor.getConfiguration().getTypeHierarchy(); |
| 61 |
Expression arg = arguments[0]; |
| 62 |
if (th.isSubType(arg.getItemType(), BuiltInAtomicType.STRING) && |
| 63 |
arg.getCardinality() == StaticProperty.EXACTLY_ONE) { |
| 64 |
return arg; |
| 65 |
} |
| 66 |
if (arg instanceof SimpleNodeConstructor) { |
| 67 |
return ((SimpleNodeConstructor) arg).getSelect(); |
| 68 |
} |
| 69 |
return null; |
| 70 |
} |
| 71 |
|
| 72 |
public String getCompilerName() { |
| 73 |
return "StringFnCompiler"; |
| 74 |
} |
| 75 |
|
| 76 |
public String getStreamerName() { |
| 77 |
return "StringFn"; |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
} |
| 82 |
|