Debian Codegraph @

net/sf/saxon/functions/SubstringAfter.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.lib.SubstringMatcher;
12 import net.sf.saxon.om.Sequence;
13 import net.sf.saxon.trans.XPathException;
14 import net.sf.saxon.value.StringValue;
15
16 /**
17 * Implements the fn:substring-after() function with the collation already known
18 */
19 public class SubstringAfter extends CollatingFunctionFixed {
20
21 @Override
22 public boolean isSubstringMatchingFunction() {
23 return true;
24 }
25
26 /**
27 * Evaluate the expression
28 *
29 * @param context the dynamic evaluation context
30 * @param arguments the values of the arguments, supplied as Sequences
31 * @return the result of the evaluation, in the form of a Sequence
32 * @throws net.sf.saxon.trans.XPathException
33 * if a dynamic error occurs during the evaluation of the expression
34 */
35 public StringValue call(XPathContext context, Sequence[] arguments) throws XPathException {
36 StringValue arg1 = (StringValue) arguments[0].head();
37 StringValue arg2 = (StringValue) arguments[1].head();
38 return substringAfter(arg1, arg2, (SubstringMatcher)getStringCollator());
39 }
40
41 private static StringValue substringAfter(StringValue arg1, StringValue arg2, SubstringMatcher collator) {
42 if (arg1 == null) {
43 arg1 = StringValue.EMPTY_STRING;
44 }
45 if (arg2 == null) {
46 arg2 = StringValue.EMPTY_STRING;
47 }
48 if (arg2.isZeroLength()) {
49 return arg1;
50 }
51 if (arg1.isZeroLength()) {
52 return StringValue.EMPTY_STRING;
53 }
54
55 String s1 = arg1.getStringValue();
56 String s2 = arg2.getStringValue();
57
58 String result = collator.substringAfter(s1, s2);
59 StringValue s = StringValue.makeStringValue(result);
60 if (arg1.isKnownToContainNoSurrogates()) {
61 s.setContainsNoSurrogates();
62 }
63 return s;
64 }
65
66 public String getCompilerName() {
67 return "SubstringAfterCompiler";
68 }
69
70 }