Search in sources :

Example 61 with Array

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

the class ListUtil method listToStringArray.

public static String[] listToStringArray(String list, String delimiter) {
    Array array = ListUtil.listToArrayRemoveEmpty(list, delimiter);
    String[] arr = new String[array.size()];
    for (int i = 0; i < arr.length; i++) {
        arr[i] = Caster.toString(array.get(i + 1, ""), "");
    }
    return arr;
}
Also used : Array(lucee.runtime.type.Array)

Example 62 with Array

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

the class ListUtil method listContains.

/* *
	 * returns if a value of the list contains given value, ignore case, ignore empty values
	 * @param list list to search in
	 * @param value value to serach
	 * @param delimiter delimiter of the list
	 * @return position in list or 0
	
	public static int listContainsIgnoreEmptyNoCase(String list, String value, String delimiter) {
		if(StringUtil.isEmpty(value)) return -1;
		Array arr=listToArrayRemoveEmpty(list,delimiter);
		int count=0;
		int len=arr.size();
		
		for(int i=1;i<=len;i++) {
			String item=arr.get(i,"").toString();
			if(StringUtil.indexOfIgnoreCase(item, value)!=-1) return count;
			count++;
		}
		return -1;
	} */
/**
 * returns if a value of the list contains given value, case sensitive
 * @param list list to search in
 * @param value value to serach
 * @param delimiter delimiter of the list
 * @return position in list or 0
 */
public static int listContains(String list, String value, String delimiter, boolean includeEmptyFields, boolean multiCharacterDelimiter) {
    if (StringUtil.isEmpty(value))
        return -1;
    Array arr = listToArray(list, delimiter, includeEmptyFields, multiCharacterDelimiter);
    int len = arr.size();
    for (int i = 1; i <= len; i++) {
        if (arr.get(i, "").toString().indexOf(value) != -1)
            return i - 1;
    }
    return -1;
}
Also used : Array(lucee.runtime.type.Array)

Example 63 with Array

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

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

the class ReplaceList method _call.

static String _call(PageContext pc, String str, String list1, String list2, String delimiter_list1, String delimiter_list2, boolean ignoreCase, boolean includeEmptyFields) {
    if (delimiter_list1 == null)
        delimiter_list1 = ",";
    if (delimiter_list2 == null)
        delimiter_list2 = ",";
    Array arr1 = ListUtil.listToArray(list1, delimiter_list1, includeEmptyFields, false);
    Array arr2 = ListUtil.listToArray(list2, delimiter_list2, includeEmptyFields, false);
    Iterator<Object> it1 = arr1.valueIterator();
    Iterator<Object> it2 = arr2.valueIterator();
    while (it1.hasNext()) {
        str = StringUtil.replace(str, Caster.toString(it1.next(), null), ((it2.hasNext()) ? Caster.toString(it2.next(), null) : ""), false, ignoreCase);
    }
    return str;
}
Also used : Array(lucee.runtime.type.Array)

Example 65 with Array

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

the class StructCopy method call.

public static Object call(PageContext pc, Struct src) throws PageException {
    Collection trg = (Collection) Duplicator.duplicate(src, false);
    Collection.Key[] keys = CollectionUtil.keys(trg);
    Collection.Key key;
    Object o;
    for (int i = 0; i < keys.length; i++) {
        key = keys[i];
        o = src.get(key, null);
        if (o instanceof Array)
            trg.set(key, Duplicator.duplicate(o, false));
    }
    return trg;
}
Also used : Array(lucee.runtime.type.Array) Collection(lucee.runtime.type.Collection)

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