001 /** 002 * Implements the Cold Fusion Function arraytolist 003 */ 004 package railo.runtime.functions.list; 005 006 import railo.runtime.PageContext; 007 import railo.runtime.exp.PageException; 008 import railo.runtime.ext.function.Function; 009 import railo.runtime.op.Caster; 010 import railo.runtime.type.Array; 011 012 public final class ArrayToList implements Function { 013 public static String call(PageContext pc , Array array) throws PageException { 014 return call(pc,array,','); 015 } 016 public static String call(PageContext pc , Array array, String delimeter) throws PageException { 017 if(delimeter.length()==1) return call(pc,array,delimeter.charAt(0)); 018 int len=array.size(); 019 if(len==0) return ""; 020 if(len==1)return Caster.toString(array.getE(1)); 021 022 Object o=array.get(1,null); 023 StringBuffer sb=new StringBuffer(o==null?"":Caster.toString(o)); 024 for(int i=2;i<=len;i++) { 025 sb.append(delimeter); 026 o=array.get(i,null); 027 sb.append(o==null?"":Caster.toString(o)); 028 } 029 return sb.toString(); 030 } 031 public static String call(PageContext pc , Array array, char delimeter) throws PageException { 032 int len=array.size(); 033 if(len==0) return ""; 034 if(len==1)return Caster.toString(array.getE(1)); 035 036 Object o=array.get(1,null); 037 StringBuffer sb=new StringBuffer(o==null?"":Caster.toString(o)); 038 for(int i=2;i<=len;i++) { 039 sb.append(delimeter); 040 o=array.get(i,null); 041 sb.append(o==null?"":Caster.toString(o)); 042 } 043 return sb.toString(); 044 } 045 }