Debian Codegraph @

net/sf/saxon/functions/RegexFunctionSansFlags.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.Configuration;
11 import net.sf.saxon.expr.Expression;
12 import net.sf.saxon.expr.StringLiteral;
13 import net.sf.saxon.expr.XPathContext;
14 import net.sf.saxon.om.Sequence;
15 import net.sf.saxon.trans.XPathException;
16 import net.sf.saxon.value.StringValue;
17
18 /**
19 * This class implements any of the functions matches(), replace(), tokenize(), analyze-string(), in which the
20 * final "flags" argument is omitted.
21 */
22 public class RegexFunctionSansFlags extends SystemFunction {
23
24 private SystemFunction addFlagsArgument() {
25 Configuration config = getRetainedStaticContext().getConfiguration();
26 SystemFunction fixed = config.makeSystemFunction(
27 getFunctionName().getLocalPart(), getArity() + 1);
28
29 fixed.setRetainedStaticContext(getRetainedStaticContext());
30 return fixed;
31 }
32
33 /**
34 * Make an expression that either calls this function, or that is equivalent to a call
35 * on this function
36 *
37 * @param arguments the supplied arguments to the function call
38 * @return either a function call on this function, or an expression that delivers
39 * the same result
40 */
41 @Override
42 public Expression makeFunctionCall(Expression... arguments) {
43 SystemFunction withFlags = addFlagsArgument();
44 Expression[] newArgs = new Expression[arguments.length + 1];
45 System.arraycopy(arguments, 0, newArgs, 0, arguments.length);
46 newArgs[arguments.length] = new StringLiteral("");
47 return withFlags.makeFunctionCall(newArgs);
48 }
49
50 /**
51 * Invoke the function. Used only for dynamic calls.
52 *
53 * @param context the XPath dynamic evaluation context
54 * @param args the actual arguments to be supplied
55 * @return the result of invoking the function
56 * @throws net.sf.saxon.trans.XPathException if a dynamic error occurs within the function
57 */
58 public Sequence<?> call(XPathContext context, Sequence[] args) throws XPathException {
59 SystemFunction withFlags = addFlagsArgument();
60 Sequence[] newArgs = new Sequence[args.length + 1];
61 System.arraycopy(args, 0, newArgs, 0, args.length);
62 newArgs[args.length] = StringValue.EMPTY_STRING;
63 return withFlags.call(context, newArgs);
64 }
65 }
66