001    /**
002     * Implements the CFML Function rereplace
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 REReplace implements Function {
015    
016            public static String call(String string, String regExp, String replace) throws ExpressionException { // MUST is this really needed?
017                try {
018                            return Perl5Util.replace(string,regExp,replace,true,false);
019                    } catch (MalformedPatternException e) {
020                            throw new ExpressionException("reReplace"+"second"+"regularExpression"+e.getMessage());
021                    }
022            }
023            public static String call(PageContext pc , String string, String regExp, String replace) throws ExpressionException {
024                try {
025                            return Perl5Util.replace(string,regExp,replace,true,false);
026                    } catch (MalformedPatternException e) {
027                            throw new FunctionException(pc,"reReplace",2,"regularExpression",e.getMessage());
028                    }
029            }
030            public static String call(PageContext pc , String string, String regExp, String replace, String scope) throws ExpressionException {
031                    try {
032                            if(scope.equalsIgnoreCase("all"))return Perl5Util.replace(string,regExp,replace,true,true);
033                            return Perl5Util.replace(string,regExp,replace,true,false);
034                    } catch (MalformedPatternException e) {
035                        throw new FunctionException(pc,"reReplace",2,"regularExpression",e.getMessage());
036                    }
037            }
038    
039    }
040