Search in sources :

Example 36 with ArrayImpl

use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.

the class ListUtil method listToArray.

/**
 * casts a list to Array object
 * @param list list to cast
 * @param delimiter delimter of the list
 * @return Array Object
 */
public static Array listToArray(String list, char delimiter) {
    if (list.length() == 0)
        return new ArrayImpl();
    int len = list.length();
    int last = 0;
    Array array = new ArrayImpl();
    try {
        for (int i = 0; i < len; i++) {
            if (list.charAt(i) == delimiter) {
                array.append(list.substring(last, i));
                last = i + 1;
            }
        }
        if (last <= len)
            array.append(list.substring(last));
    } catch (PageException e) {
    }
    return array;
}
Also used : Array(lucee.runtime.type.Array) PageException(lucee.runtime.exp.PageException) ArrayImpl(lucee.runtime.type.ArrayImpl)

Example 37 with ArrayImpl

use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.

the class ListUtil method listToArrayTrim.

/**
 * casts a list to Array object, remove all empty items at start and end of the list
 * @param list list to cast
 * @param delimiter delimter of the list
 * @return Array Object
 */
public static Array listToArrayTrim(String list, char delimiter) {
    if (list.length() == 0)
        return new ArrayImpl();
    // remove at start
    while (list.indexOf(delimiter) == 0) {
        list = list.substring(1);
    }
    int len = list.length();
    if (len == 0)
        return new ArrayImpl();
    while (list.lastIndexOf(delimiter) == len - 1) {
        list = list.substring(0, len - 1 < 0 ? 0 : len - 1);
        len = list.length();
    }
    return listToArray(list, delimiter);
}
Also used : ArrayImpl(lucee.runtime.type.ArrayImpl)

Example 38 with ArrayImpl

use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.

the class ListUtil method listWithQuotesToArray.

/**
 * casts a list to Array object, the list can be have quoted (",') arguments and delimter in this arguments are ignored. quotes are not removed
 * example:
 *  listWithQuotesToArray("aab,a'a,b',a\"a,b\"",",","\"'") will be translated to ["aab","a'a,b'","a\"a,b\""]
 *
 * @param list list to cast
 * @param delimiter delimter of the list
 * @param quotes quotes of the list
 * @return Array Object
 */
public static Array listWithQuotesToArray(String list, String delimiter, String quotes) {
    if (list.length() == 0)
        return new ArrayImpl();
    int len = list.length();
    int last = 0;
    char[] del = delimiter.toCharArray();
    char[] quo = quotes.toCharArray();
    char c;
    char inside = 0;
    ArrayImpl array = new ArrayImpl();
    // try{
    for (int i = 0; i < len; i++) {
        c = list.charAt(i);
        for (int y = 0; y < quo.length; y++) {
            if (c == quo[y]) {
                if (c == inside)
                    inside = 0;
                else if (inside == 0)
                    inside = c;
                continue;
            }
        }
        for (int y = 0; y < del.length; y++) {
            if (inside == 0 && c == del[y]) {
                array.appendEL(list.substring(last, i));
                last = i + 1;
                break;
            }
        }
    }
    if (last <= len)
        array.appendEL(list.substring(last));
    // }catch(PageException e){}
    return array;
}
Also used : ArrayImpl(lucee.runtime.type.ArrayImpl)

Example 39 with ArrayImpl

use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.

the class QueryUtil method duplicate2QueryColumnImpl.

public static QueryColumnImpl duplicate2QueryColumnImpl(QueryImpl targetQuery, QueryColumn col, boolean deepCopy) {
    if (col instanceof QueryColumnImpl)
        return ((QueryColumnImpl) col).cloneColumnImpl(deepCopy);
    // fill array for column
    Array content = new ArrayImpl();
    int len = col.size();
    for (int i = 1; i <= len; i++) {
        content.setEL(i, col.get(i, null));
    }
    // create and return column
    try {
        return new QueryColumnImpl(targetQuery, col.getKey(), content, col.getType());
    } catch (PageException e) {
        throw new PageRuntimeException(e);
    }
}
Also used : Array(lucee.runtime.type.Array) PageException(lucee.runtime.exp.PageException) QueryColumnImpl(lucee.runtime.type.QueryColumnImpl) ArrayImpl(lucee.runtime.type.ArrayImpl) PageRuntimeException(lucee.runtime.exp.PageRuntimeException)

Example 40 with ArrayImpl

use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.

the class StructFindKey method _call.

private static Array _call(PageContext pc, Struct struct, String value, boolean all) throws PageException {
    Array array = new ArrayImpl();
    getValues(array, struct, value, all, "");
    return array;
}
Also used : ListAsArray(lucee.runtime.type.wrap.ListAsArray) Array(lucee.runtime.type.Array) ArrayImpl(lucee.runtime.type.ArrayImpl)

Aggregations

ArrayImpl (lucee.runtime.type.ArrayImpl)100 Array (lucee.runtime.type.Array)79 Struct (lucee.runtime.type.Struct)33 StructImpl (lucee.runtime.type.StructImpl)24 PageException (lucee.runtime.exp.PageException)14 Entry (java.util.Map.Entry)13 Key (lucee.runtime.type.Collection.Key)12 ArgumentIntKey (lucee.runtime.type.scope.ArgumentIntKey)8 IOException (java.io.IOException)7 Iterator (java.util.Iterator)7 ArrayList (java.util.ArrayList)6 ListIterator (java.util.ListIterator)6 FunctionException (lucee.runtime.exp.FunctionException)6 ForEachQueryIterator (lucee.runtime.type.it.ForEachQueryIterator)6 ApplicationException (lucee.runtime.exp.ApplicationException)5 ExpressionException (lucee.runtime.exp.ExpressionException)5 Query (lucee.runtime.type.Query)5 QueryImpl (lucee.runtime.type.QueryImpl)5 ListAsArray (lucee.runtime.type.wrap.ListAsArray)5 NodeList (org.w3c.dom.NodeList)5