001    /**
002     * Implements the Cold Fusion Function replace
003     */
004    package railo.runtime.functions.string;
005    
006    import railo.commons.lang.StringUtil;
007    import railo.runtime.PageContext;
008    import railo.runtime.exp.ExpressionException;
009    import railo.runtime.ext.function.Function;
010    
011    public final class Replace implements Function {
012            
013            public static String call(PageContext pc , String str, String sub1, String sub2) {
014                    return StringUtil.replace(str,sub1,sub2,true);
015            }
016    
017            public static String call(PageContext pc , String str, String sub1, String sub2, String scope) throws ExpressionException {
018                    if(sub1.length()==0)
019                            throw new ExpressionException("the string length of Parameter 2 of function replace which is now ["+sub1.length()+"] must be greater than 0");
020                    return StringUtil.replace(str,sub1,sub2,!scope.equalsIgnoreCase("all"));
021            }
022    }