Search in sources :

Example 6 with StringList

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;
}
Also used : StringList(lucee.commons.lang.StringList)

Example 7 with StringList

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);
}
Also used : StringList(lucee.commons.lang.StringList)

Example 8 with StringList

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;
}
Also used : StringList(lucee.commons.lang.StringList)

Example 9 with StringList

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();
}
Also used : StringList(lucee.commons.lang.StringList)

Example 10 with StringList

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;
}
Also used : PageException(lucee.runtime.exp.PageException) StringList(lucee.commons.lang.StringList) ParserString(lucee.commons.lang.ParserString)

Aggregations

StringList (lucee.commons.lang.StringList)22 ParserString (lucee.commons.lang.ParserString)10 PageException (lucee.runtime.exp.PageException)4 Collection (lucee.runtime.type.Collection)2 URI (java.net.URI)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 CastableStruct (lucee.runtime.type.CastableStruct)1 Struct (lucee.runtime.type.Struct)1 VariableReference (lucee.runtime.type.ref.VariableReference)1 CollectionKey (lucee.transformer.bytecode.expression.type.CollectionKey)1 CollectionKeyArray (lucee.transformer.bytecode.expression.type.CollectionKeyArray)1 Argument (lucee.transformer.bytecode.expression.var.Argument)1 Expression (lucee.transformer.expression.Expression)1 LitString (lucee.transformer.expression.literal.LitString)1 Version (org.osgi.framework.Version)1