001 /** 002 * Implements the Cold Fusion Function repeatstring 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 import railo.runtime.op.Caster; 011 012 public final class RepeatString implements Function { 013 public static String call(PageContext pc , String str, double count) throws ExpressionException { 014 if(count<0) throw new ExpressionException("Parameter 2 of function repeatString which is now ["+Caster.toString(count)+"] must be a non-negative integer"); 015 return StringUtil.repeatString(str,(int)count); 016 } 017 public static String _call(PageContext pc , String str, double count) throws ExpressionException { 018 int len=(int) count; 019 if(len<0) throw new ExpressionException("Parameter 2 of function repeatString which is now ["+len+"] must be a non-negative integer"); 020 char[] chars=str.toCharArray(); 021 StringBuffer cb=new StringBuffer(chars.length*len); 022 for(int i=0;i<len;i++)cb.append(chars); 023 return cb.toString(); 024 } 025 public static StringBuffer call(StringBuffer sb,String str, double count) throws ExpressionException { 026 int len=(int) count; 027 if(len<0) throw new ExpressionException("Parameter 1 of function repeatString which is now ["+len+"] must be a non-negative integer"); 028 029 for(int i=0;i<len;i++)sb.append(str); 030 return sb; 031 } 032 public static StringBuffer call(StringBuffer sb,char c, double count) throws ExpressionException { 033 int len=(int) count; 034 if(len<0) throw new ExpressionException("Parameter 1 of function repeatString which is now ["+len+"] must be a non-negative integer"); 035 036 for(int i=0;i<len;i++)sb.append(c); 037 return sb; 038 } 039 }