001 /** 002 * Implements the Cold Fusion Function replacenocase 003 */ 004 package railo.runtime.functions.string; 005 006 import railo.runtime.PageContext; 007 import railo.runtime.exp.ExpressionException; 008 import railo.runtime.ext.function.Function; 009 010 public final class ReplaceNoCase implements Function { 011 012 public static String call(PageContext pc , String str, String sub1, String sub2) throws ExpressionException { 013 return call(pc , str, sub1, sub2, "one"); 014 } 015 016 public static String call(PageContext pc , String str, String sub1, String sub2, String scope) throws ExpressionException { 017 if(sub1.length()==0) 018 throw new ExpressionException("the string length of Parameter 2 of function replaceNoCase which is now ["+sub1.length()+"] must be greater than 0"); 019 020 //if(sub1.equals(sub2)) return str; 021 boolean doAll=scope.equalsIgnoreCase("all"); 022 023 024 String lcStr=str.toLowerCase(); 025 String lcSub1=sub1.toLowerCase(); 026 StringBuffer sb=new StringBuffer(); 027 int start=0; 028 int pos; 029 int sub1Length=sub1.length(); 030 while((pos=lcStr.indexOf(lcSub1,start))!=-1){ 031 sb.append(str.substring(start,pos)); 032 sb.append(sub2); 033 start=pos+sub1Length; 034 if(!doAll)break; 035 } 036 sb.append(str.substring(start)); 037 038 return sb.toString(); 039 } 040 041 042 }