Debian Codegraph @

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