Debian Codegraph @

net/sf/saxon/functions/NormalizeSpace_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.SystemFunctionCall;
12 import net.sf.saxon.expr.XPathContext;
13 import net.sf.saxon.om.Item;
14 import net.sf.saxon.om.One;
15 import net.sf.saxon.om.ZeroOrOne;
16 import net.sf.saxon.trans.XPathException;
17 import net.sf.saxon.value.AtomicValue;
18 import net.sf.saxon.value.StringValue;
19 import net.sf.saxon.value.Whitespace;
20
21 /**
22 * Implement the XPath normalize-space() function
23 */
24
25 public class NormalizeSpace_1 extends ScalarSystemFunction {
26
27 @Override
28 public ZeroOrOne<? extends AtomicValue> resultWhenEmpty() {
29 return One.string("");
30 }
31
32 @Override
33 public AtomicValue evaluate(Item arg, XPathContext context) throws XPathException {
34 return normalizeSpace((StringValue) arg);
35 }
36
37 public static StringValue normalizeSpace(StringValue sv) {
38 if (sv == null) {
39 return StringValue.EMPTY_STRING;
40 }
41 return StringValue.makeStringValue(
42 Whitespace.collapseWhitespace(sv.getStringValueCS()));
43 }
44
45 @Override
46 public Expression makeFunctionCall(Expression[] arguments) {
47 return new SystemFunctionCall(this, arguments) {
48 public boolean effectiveBooleanValue(XPathContext c) throws XPathException {
49 AtomicValue sv = (AtomicValue) getArg(0).evaluateItem(c);
50 if (sv == null) {
51 return false;
52 }
53 CharSequence cs = sv.getStringValueCS();
54 return !Whitespace.isWhite(cs);
55 }
56 };
57 }
58
59 public String getCompilerName() {
60 return "NormalizeSpaceCompiler";
61 }
62
63 }
64