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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations