1 package com.icl.saxon.functions; 2 import com.icl.saxon.*; 3 import com.icl.saxon.expr.*; 4 5 import java.util.*; 6 7 8 9 public class SubstringAfter extends Function { 10 11 public String getName() { 12 return "substring-after"; 13 }; 14 15 19 20 public int getDataType() { 21 return Value.STRING; 22 } 23 24 27 28 public Expression simplify() throws XPathException { 29 int numArgs = checkArgumentCount(2,2); 30 argument[0] = argument[0].simplify(); 31 argument[1] = argument[1].simplify(); 32 boolean fixed = (argument[0] instanceof Value) && (argument[1] instanceof Value); 33 34 if (fixed) { 35 return evaluate(null); 36 } 37 return this; 38 } 39 40 43 44 public String evaluateAsString(Context context) throws XPathException { 45 46 String s = argument[0].evaluateAsString(context); 47 String a = argument[1].evaluateAsString(context); 48 return after(s, a); 49 } 50 51 54 55 public Value evaluate(Context c) throws XPathException { 56 return new StringValue(evaluateAsString(c)); 57 } 58 59 60 63 64 public int getDependencies() { 65 int dep = argument[0].getDependencies() | argument[1].getDependencies(); 66 return dep; 67 } 68 69 72 73 public Expression reduce(int dep, Context c) throws XPathException { 74 SubstringAfter f = new SubstringAfter(); 75 f.addArgument(argument[0].reduce(dep, c)); 76 f.addArgument(argument[1].reduce(dep, c)); 77 f.setStaticContext(getStaticContext()); 78 return f.simplify(); 79 } 80 81 85 86 private static String after(String s1, String s2) { 87 int i = s1.indexOf(s2); 88 if (i<0) return ""; 89 return s1.substring(i+s2.length()); 90 } 91 92 } 93 94 95 96 | Popular Tags |