use of lucee.commons.lang.StringList in project Lucee by lucee.
the class ListUtil method toWordList.
public static StringList toWordList(String list) {
if (list.length() == 0)
return new StringList();
int len = list.length();
int last = 0;
char c, l = 0;
StringList rtn = new StringList();
for (int i = 0; i < len; i++) {
if (StringUtil.isWhiteSpace(c = list.charAt(i))) {
rtn.add(list.substring(last, i), l);
l = c;
last = i + 1;
}
}
if (last <= len)
rtn.add(list.substring(last), l);
rtn.reset();
return rtn;
}
use of lucee.commons.lang.StringList in project Lucee by lucee.
the class ListUtil method toListTrim.
/**
* @param list
* @param delimiter
* @return trimmed list
*/
public static StringList toListTrim(String list, char delimiter) {
if (list.length() == 0)
return new StringList();
// remove at start
while (list.indexOf(delimiter) == 0) {
list = list.substring(1);
}
int len = list.length();
if (len == 0)
return new StringList();
while (list.lastIndexOf(delimiter) == len - 1) {
list = list.substring(0, len - 1 < 0 ? 0 : len - 1);
len = list.length();
}
return toList(list, delimiter);
}
use of lucee.commons.lang.StringList in project Lucee by lucee.
the class ListUtil method toList.
/**
* @param list
* @param delimiter
* @return list
*/
public static StringList toList(String list, char delimiter) {
if (list.length() == 0)
return new StringList();
int len = list.length();
int last = 0;
StringList rtn = new StringList();
for (int i = 0; i < len; i++) {
if (list.charAt(i) == delimiter) {
rtn.add(list.substring(last, i));
last = i + 1;
}
}
if (last <= len)
rtn.add(list.substring(last));
rtn.reset();
return rtn;
}
use of lucee.commons.lang.StringList in project Lucee by lucee.
the class ListUtil method listToStringListRemoveEmpty.
/**
* casts a list to Array object remove Empty Elements
* @param list list to cast
* @param delimiter delimter of the list
* @return Array Object
*/
public static StringList listToStringListRemoveEmpty(String list, char delimiter) {
int len = list.length();
StringList rtn = new StringList();
if (len == 0)
return rtn.reset();
int last = 0;
for (int i = 0; i < len; i++) {
if (list.charAt(i) == delimiter) {
if (last < i)
rtn.add(list.substring(last, i));
last = i + 1;
}
}
if (last < len)
rtn.add(list.substring(last));
return rtn.reset();
}
use of lucee.commons.lang.StringList in project Lucee by lucee.
the class VariableInterpreter method parse.
/*
public static boolean isDefined(PageContext pc,String var) {
StringList list = parse(pc,new ParserString(var));
if(list==null) return false;
int scope=scopeString2Int(list.next());
Object coll =NULL;
if(scope==Scope.SCOPE_UNDEFINED) {
coll=pc.undefinedScope().get(list.current(),NULL);
if(coll==NULL) return false;
}
else {
try {
coll=pc.scope(scope);
} catch (PageException e) {
return false;
}
}
while(list.hasNext()) {
coll=pc.getVariableUtil().get(pc,coll,list.next(),NULL);
//print.out(coll);
if(coll==NULL) return false;
}
return true;
}
*/
/**
* parse a Literal variable String and return result as String List
* @param pc Page Context
* @param ps ParserString to read
* @return Variable Definition in a String List
*/
private static StringList parse(PageContext pc, ParserString ps, boolean doLowerCase) {
String id = readIdentifier(ps, doLowerCase);
if (id == null)
return null;
StringList list = new StringList(id);
CFMLExpressionInterpreter interpreter = null;
while (true) {
if (ps.forwardIfCurrent('.')) {
id = readIdentifier(ps, doLowerCase);
if (id == null)
return null;
list.add(id);
} else if (ps.forwardIfCurrent('[')) {
if (interpreter == null)
interpreter = new CFMLExpressionInterpreter(false);
try {
list.add(Caster.toString(interpreter.interpretPart(pc, ps)));
} catch (PageException e) {
return null;
}
if (!ps.forwardIfCurrent(']'))
return null;
ps.removeSpace();
} else
break;
}
if (ps.isValidIndex())
return null;
list.reset();
return list;
}
Aggregations