| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 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 |
|
| 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 |
|