1 package net.sf.saxon.functions; 2 import net.sf.saxon.expr.Expression; 3 import net.sf.saxon.expr.StaticContext; 4 import net.sf.saxon.expr.StaticProperty; 5 import net.sf.saxon.expr.XPathContext; 6 import net.sf.saxon.instruct.RegexIterator; 7 import net.sf.saxon.om.Item; 8 import net.sf.saxon.trans.XPathException; 9 import net.sf.saxon.value.AtomicValue; 10 import net.sf.saxon.value.NumericValue; 11 import net.sf.saxon.value.StringValue; 12 13 14 public class RegexGroup extends SystemFunction implements XSLTFunction { 15 16 /** 17 * preEvaluate: this method suppresses compile-time evaluation by doing nothing 18 */ 19 20 public Expression preEvaluate(StaticContext env) { 21 return this; 22 } 23 24 /** 25 * Evaluate in a general context 26 */ 27 28 public Item evaluateItem(XPathContext c) throws XPathException { 29 AtomicValue gp0 = (AtomicValue)argument[0].evaluateItem(c); 30 NumericValue gp = (NumericValue)gp0.getPrimitiveValue(); 31 RegexIterator iter = c.getCurrentRegexIterator(); 32 if (iter == null) return null; 33 String s = iter.getRegexGroup((int)gp.longValue()); 34 if (s == null) return null; 35 return StringValue.makeStringValue(s); 36 } 37 38 /** 39 * Determine the dependencies 40 */ 41 42 public int getIntrinsicDependencies() { 43 return StaticProperty.DEPENDS_ON_REGEX_GROUP; 44 } 45 46 } 47 48 49 50 51 // 52 // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License"); 53 // you may not use this file except in compliance with the License. You may obtain a copy of the 54 // License at http://www.mozilla.org/MPL/ 55 // 56 // Software distributed under the License is distributed on an "AS IS" basis, 57 // WITHOUT WARRANTY OF ANY KIND, either express or implied. 58 // See the License for the specific language governing rights and limitations under the License. 59 // 60 // The Original Code is: all this file. 61 // 62 // The Initial Developer of the Original Code is Michael H. Kay. 63 // 64 // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved. 65 // 66 // Contributor(s): none. 67 // 68