use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.
the class ArgumentImpl method toArray.
/**
* converts a argument scope to a regular array
* @param arg argument scope to convert
* @return resulting array
*/
public static Array toArray(Argument arg) {
ArrayImpl trg = new ArrayImpl();
int[] keys = arg.intKeys();
for (int i = 0; i < keys.length; i++) {
trg.setEL(keys[i], arg.get(keys[i], null));
}
return trg;
}
use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.
the class ScopeSupport method _fill.
private Struct _fill(final Struct parent, String name, Object value, boolean isLast, boolean scriptProteced, boolean sameAsArray) {
Object curr;
boolean isArrayDef = sameAsArray;
Collection.Key key = KeyImpl.init(name);
// script protect
if (scriptProteced && value instanceof String) {
value = ScriptProtect.translate((String) value);
}
if (name.length() > 2 && name.endsWith("[]")) {
isArrayDef = true;
name = name.substring(0, name.length() - 2);
key = KeyImpl.getInstance(name);
curr = parent.get(key, null);
} else {
curr = parent.get(key, null);
}
if (curr == null) {
if (isArrayDef) {
Array arr = new ArrayImpl();
arr.appendEL(value);
parent.setEL(key, arr);
} else
parent.setEL(key, value);
} else if (curr instanceof Array) {
((Array) curr).appendEL(value);
} else if (curr instanceof CastableStruct) {
if (isLast)
((CastableStruct) curr).setValue(value);
else
return (Struct) curr;
} else if (curr instanceof Struct) {
if (isLast)
parent.setEL(key, value);
else
return (Struct) curr;
} else if (curr instanceof String) {
if (isArrayDef) {
Array arr = new ArrayImpl();
arr.appendEL(curr);
arr.appendEL(value);
parent.setEL(key, arr);
} else if (value instanceof Struct) {
parent.setEL(key, value);
} else {
if (!StringUtil.isEmpty(value)) {
String existing = Caster.toString(curr, "");
if (StringUtil.isEmpty(existing))
parent.setEL(key, value);
else
parent.setEL(key, Caster.toString(curr, "") + ',' + value);
}
}
}
if (!isLast) {
return (Struct) value;
}
return null;
}
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, String delimiter) {
if (delimiter.length() == 1)
return listToArray(list, delimiter.charAt(0));
if (list.length() == 0)
return new ArrayImpl();
if (delimiter.length() == 0) {
int len = list.length();
ArrayImpl array = new ArrayImpl();
// ACF compatibility
array.appendEL("");
for (int i = 0; i < len; i++) {
array.appendEL(list.charAt(i));
}
// ACF compatibility
array.appendEL("");
return array;
}
int len = list.length();
int last = 0;
char[] del = delimiter.toCharArray();
char c;
ArrayImpl array = new ArrayImpl();
// try{
for (int i = 0; i < len; i++) {
c = list.charAt(i);
for (int y = 0; y < del.length; y++) {
if (c == del[y]) {
array.appendEL(list.substring(last, i));
last = i + 1;
break;
}
}
}
if (last <= len)
array.appendEL(list.substring(last));
// }catch(ExpressionException e){}
return array;
}
use of lucee.runtime.type.ArrayImpl 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.ArrayImpl 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;
}
Aggregations