001 /** 002 * Implements the CFML Function rjustify 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 RJustify implements Function { 011 public static String call(PageContext pc , String str, double length) throws ExpressionException { 012 int len=(int) length; 013 if(len<1) throw new ExpressionException("Parameter 2 of function rJustify which is now ["+len+"] must be a positive integer"); 014 else if((len-=str.length())<=0) return str; 015 else { 016 StringBuffer sb=new StringBuffer(str.length()+len); 017 for(int i=1;i<=len;i++) { 018 sb.append(' '); 019 //str=" "+str; 020 } 021 return sb.append(str).toString(); 022 } 023 } 024 }