01: package net.sf.saxon.functions;
02:
03: import net.sf.saxon.expr.Expression;
04: import net.sf.saxon.expr.StaticContext;
05: import net.sf.saxon.expr.StaticProperty;
06: import net.sf.saxon.expr.XPathContext;
07: import net.sf.saxon.instruct.RegexIterator;
08: import net.sf.saxon.om.Item;
09: import net.sf.saxon.trans.XPathException;
10: import net.sf.saxon.value.AtomicValue;
11: import net.sf.saxon.value.NumericValue;
12: import net.sf.saxon.value.StringValue;
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)
33: return null;
34: String s = iter.getRegexGroup((int) gp.longValue());
35: if (s == null)
36: return null;
37: return StringValue.makeStringValue(s);
38: }
39:
40: /**
41: * Determine the dependencies
42: */
43:
44: public int getIntrinsicDependencies() {
45: return StaticProperty.DEPENDS_ON_REGEX_GROUP;
46: }
47:
48: }
49:
50: //
51: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
52: // you may not use this file except in compliance with the License. You may obtain a copy of the
53: // License at http://www.mozilla.org/MPL/
54: //
55: // Software distributed under the License is distributed on an "AS IS" basis,
56: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
57: // See the License for the specific language governing rights and limitations under the License.
58: //
59: // The Original Code is: all this file.
60: //
61: // The Initial Developer of the Original Code is Michael H. Kay.
62: //
63: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
64: //
65: // Contributor(s): none.
66: //
|