001    /**
002     * Implements the CFML Function structkeylist
003     */
004    package railo.runtime.functions.struct;
005    
006    import java.util.Iterator;
007    
008    import railo.runtime.PageContext;
009    import railo.runtime.ext.function.Function;
010    import railo.runtime.type.Collection.Key;
011    import railo.runtime.type.Struct;
012    
013    public final class StructKeyList implements Function {
014            public static String call(PageContext pc , Struct struct) {
015                    return call(pc,struct,",");//KeyImpl.toUpperCaseList(struct.keys(), ",");
016            }
017            public static String call(PageContext pc , Struct struct, String delimiter) {
018                    //return KeyImpl.toList(CollectionUtil.keys(struct), delimiter);
019                    
020                    if(struct==null) return "";
021                    Iterator<Key> it = struct.keyIterator();
022                    
023                    // first
024                    if(!it.hasNext()) return "";
025                    StringBuilder sb=new StringBuilder();
026                    sb.append(it.next().getString());
027                    
028                    // rest
029                    if(delimiter.length()==1) {
030                            char c=delimiter.charAt(0);
031                            while(it.hasNext()){
032                                    sb.append(c);
033                                    sb.append(it.next().getString());
034                            }
035                    }
036                    else {
037                            while(it.hasNext()){
038                                    sb.append(delimiter);
039                                    sb.append(it.next().getString());
040                            }
041                    }
042                    
043                    return sb.toString();
044            }
045    }