Search in sources :

Example 56 with Array

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

the class ListUtil method listFindNoCase.

/**
 * finds a value inside a list, do not ignore case
 * @param list list to search
 * @param value value to find
 * @param delimiter delimiter of the list
 * @param trim trim the list or not
 * @return position in list (0-n) or -1
 */
public static int listFindNoCase(String list, String value, String delimiter, boolean trim) {
    Array arr = trim ? listToArrayTrim(list, delimiter) : listToArray(list, delimiter);
    int len = arr.size();
    for (int i = 1; i <= len; i++) {
        if (((String) arr.get(i, "")).equalsIgnoreCase(value))
            return i - 1;
    }
    return -1;
}
Also used : Array(lucee.runtime.type.Array)

Example 57 with Array

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

the class ListUtil method listToArray.

private static Array listToArray(String list, String delimiter, boolean multiCharDelim) {
    if (!multiCharDelim || delimiter.length() == 0)
        return listToArray(list, delimiter);
    if (delimiter.length() == 1)
        return listToArray(list, delimiter.charAt(0));
    int len = list.length();
    if (len == 0)
        return new ArrayImpl();
    Array array = new ArrayImpl();
    int from = 0;
    int index;
    int dl = delimiter.length();
    while ((index = list.indexOf(delimiter, from)) != -1) {
        array.appendEL(list.substring(from, index));
        from = index + dl;
    }
    array.appendEL(list.substring(from, len));
    return array;
}
Also used : Array(lucee.runtime.type.Array) ArrayImpl(lucee.runtime.type.ArrayImpl)

Example 58 with Array

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

the class ListUtil method listToArrayRemoveEmpty.

/**
 * casts a list to Array object remove Empty Elements
 * @param list list to cast
 * @param delimiter delimter of the list
 * @return Array Object
 */
private static Array listToArrayRemoveEmpty(String list, String delimiter, boolean multiCharDelim) {
    if (!multiCharDelim || delimiter.length() == 0)
        return listToArrayRemoveEmpty(list, delimiter);
    if (delimiter.length() == 1)
        return listToArrayRemoveEmpty(list, delimiter.charAt(0));
    int len = list.length();
    if (len == 0)
        return new ArrayImpl();
    Array array = new ArrayImpl();
    int from = 0;
    int index;
    int dl = delimiter.length();
    while ((index = list.indexOf(delimiter, from)) != -1) {
        if (from < index)
            array.appendEL(list.substring(from, index));
        from = index + dl;
    }
    if (from < len)
        array.appendEL(list.substring(from, len));
    return array;
}
Also used : Array(lucee.runtime.type.Array) ArrayImpl(lucee.runtime.type.ArrayImpl)

Example 59 with Array

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

the class ListUtil method listFindForSwitch.

public static int listFindForSwitch(String list, String value, String delimiter) {
    if (list.indexOf(delimiter) == -1 && list.equalsIgnoreCase(value))
        return 1;
    Array arr = listToArray(list, delimiter);
    int len = arr.size();
    for (int i = 1; i <= len; i++) {
        if (((String) arr.get(i, "")).equalsIgnoreCase(value))
            return i;
    }
    return -1;
}
Also used : Array(lucee.runtime.type.Array)

Example 60 with Array

use of lucee.runtime.type.Array 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)

Aggregations

Array (lucee.runtime.type.Array)169 ArrayImpl (lucee.runtime.type.ArrayImpl)79 Struct (lucee.runtime.type.Struct)49 StructImpl (lucee.runtime.type.StructImpl)25 Iterator (java.util.Iterator)24 PageException (lucee.runtime.exp.PageException)23 Entry (java.util.Map.Entry)22 ArrayList (java.util.ArrayList)20 Key (lucee.runtime.type.Collection.Key)20 ListIterator (java.util.ListIterator)16 Query (lucee.runtime.type.Query)16 List (java.util.List)14 ApplicationException (lucee.runtime.exp.ApplicationException)14 FunctionException (lucee.runtime.exp.FunctionException)14 ForEachQueryIterator (lucee.runtime.type.it.ForEachQueryIterator)14 Resource (lucee.commons.io.res.Resource)13 IOException (java.io.IOException)12 Collection (lucee.runtime.type.Collection)10 QueryImpl (lucee.runtime.type.QueryImpl)10 JavaObject (lucee.runtime.java.JavaObject)8