Debian Codegraph @

net/sf/saxon/functions/String_1.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.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 * Implement XPath function string() with a single argument
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 * Allow the function to create an optimized call based on the values of the actual arguments
50 *
51 * @param visitor the expression visitor
52 * @param contextInfo information about the context item
53 * @param arguments the supplied arguments to the function call
54 * @return either a function call on this function, or an expression that delivers
55 * the same result, or null indicating that no optimization has taken place
56 * @throws net.sf.saxon.trans.XPathException if an error is detected
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