001    /**
002     * Implements the CFML Function refind
003     */
004    package railo.runtime.functions.string;
005    
006    import org.apache.oro.text.regex.MalformedPatternException;
007    
008    import railo.runtime.PageContext;
009    import railo.runtime.exp.ExpressionException;
010    import railo.runtime.exp.FunctionException;
011    import railo.runtime.ext.function.Function;
012    import railo.runtime.regex.Perl5Util;
013    
014    public final class REFind implements Function {
015            public static Object call(PageContext pc , String regExpr, String str) throws ExpressionException {
016                    return call(pc,regExpr,str,1,false);
017            }
018            public static Object call(PageContext pc , String regExpr, String str, double start) throws ExpressionException {
019                    return call(pc,regExpr,str,start,false);
020            }
021            public static Object call(PageContext pc , String regExpr, String str, double start, boolean returnsubexpressions) throws ExpressionException {
022                    try {
023                            if(returnsubexpressions)
024                                    return Perl5Util.find(regExpr,str,(int)start,true);
025                            return new Double(Perl5Util.indexOf(regExpr,str,(int)start,true));
026                    } catch (MalformedPatternException e) {
027                            throw new FunctionException(pc,"reFind",1,"regularExpression",e.getMessage());
028                    }
029            }
030    }