Search in sources :

Example 66 with ExpressionException

use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.

the class Mid method call.

public static String call(PageContext pc, String str, double start, double count) throws ExpressionException {
    int s = (int) (start - 1);
    int c = (int) count;
    if (s < 0)
        throw new ExpressionException("Parameter 2 of function mid which is now [" + (s + 1) + "] must be a positive integer");
    if (c == -1)
        c = str.length();
    else if (c < -1)
        throw new ExpressionException("Parameter 3 of function mid which is now [" + c + "] must be a non-negative integer or -1 (for string length)");
    c += s;
    if (s > str.length())
        return "";
    else if (c >= str.length())
        return str.substring(s);
    else {
        return str.substring(s, c);
    }
}
Also used : ExpressionException(lucee.runtime.exp.ExpressionException)

Example 67 with ExpressionException

use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.

the class MonthAsString method call.

protected static String call(double month, Locale locale, boolean _short) throws ExpressionException {
    int m = (int) month;
    if (m >= 1 && m <= 12) {
        DateFormatSymbols dfs = new DateFormatSymbols(locale);
        String[] months = _short ? dfs.getShortMonths() : dfs.getMonths();
        return months[m - 1];
    }
    throw new ExpressionException("invalid month definition in function monthAsString, must be between 1 and 12 now [" + month + "]");
}
Also used : DateFormatSymbols(java.text.DateFormatSymbols) ExpressionException(lucee.runtime.exp.ExpressionException)

Example 68 with ExpressionException

use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.

the class ParseNumber method invoke.

public static double invoke(String strNumber, String strRadix) throws PageException {
    strNumber = strNumber.trim();
    int radix = DEC;
    if (strRadix == null) {
        if (StringUtil.startsWithIgnoreCase(strNumber, "0x")) {
            radix = HEX;
            strNumber = strNumber.substring(2);
        } else if (strNumber.startsWith("#")) {
            radix = HEX;
            strNumber = strNumber.substring(1);
        } else if (strNumber.startsWith("0") && strNumber.length() > 1) {
            radix = OCT;
            strNumber = strNumber.substring(1);
        }
    } else {
        strRadix = strRadix.trim().toLowerCase();
        if (strRadix.startsWith("bin"))
            radix = BIN;
        else if (strRadix.startsWith("oct"))
            radix = OCT;
        else if (strRadix.startsWith("dec"))
            radix = DEC;
        else if (strRadix.startsWith("hex")) {
            if (StringUtil.startsWithIgnoreCase(strNumber, "0x"))
                strNumber = strNumber.substring(2);
            else if (strNumber.startsWith("#"))
                strNumber = strNumber.substring(1);
            radix = HEX;
        } else
            throw new ExpressionException("invalid radix defintions, valid vales are [bin,oct,dec,hex]");
    }
    if (radix == OCT && strNumber.indexOf('9') != -1)
        throw new ExpressionException("digit [9] is out of range for a octal number");
    if (strNumber.indexOf('.') != -1 && radix != DEC)
        throw new ExpressionException("the radix con only be [dec] for floating point numbers");
    if (radix == DEC) {
        return Caster.toDoubleValue(strNumber);
    }
    return Integer.parseInt(strNumber, radix);
}
Also used : ExpressionException(lucee.runtime.exp.ExpressionException)

Example 69 with ExpressionException

use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.

the class RemoveChars method call.

public static String call(PageContext pc, String str, double s, double l) throws ExpressionException {
    int start = (int) s;
    int length = (int) l;
    int strLength = str.length();
    // check param 2
    if (start < 1 || start > strLength)
        throw new ExpressionException("Parameter 2 of function removeChars which is now [" + start + "] must be a greater 0 and less than the length of the first parameter");
    // check param 3
    if (length < 0)
        throw new ExpressionException("Parameter 3 of function removeChars which is now [" + length + "] must be a non-negative integer");
    if (strLength == 0)
        return "";
    String rtn = str.substring(0, start - 1);
    if (start + length <= strLength)
        rtn += str.substring(start + length - 1);
    return rtn;
}
Also used : ExpressionException(lucee.runtime.exp.ExpressionException)

Example 70 with ExpressionException

use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.

the class RepeatString method _call.

public static String _call(PageContext pc, String str, double count) throws ExpressionException {
    int len = (int) count;
    if (len < 0)
        throw new ExpressionException("Parameter 2 of function repeatString which is now [" + len + "] must be a non-negative integer");
    char[] chars = str.toCharArray();
    StringBuilder cb = new StringBuilder(chars.length * len);
    for (int i = 0; i < len; i++) cb.append(chars);
    return cb.toString();
}
Also used : ExpressionException(lucee.runtime.exp.ExpressionException)

Aggregations

ExpressionException (lucee.runtime.exp.ExpressionException)136 Element (org.w3c.dom.Element)24 Key (lucee.runtime.type.Collection.Key)15 SecurityException (lucee.runtime.exp.SecurityException)13 ArrayList (java.util.ArrayList)12 Struct (lucee.runtime.type.Struct)12 List (java.util.List)11 Collection (lucee.runtime.type.Collection)11 Entry (java.util.Map.Entry)10 Node (org.w3c.dom.Node)10 Resource (lucee.commons.io.res.Resource)9 Iterator (java.util.Iterator)8 PageException (lucee.runtime.exp.PageException)8 Map (java.util.Map)7 CasterException (lucee.runtime.exp.CasterException)7 NodeList (org.w3c.dom.NodeList)7 PageContextImpl (lucee.runtime.PageContextImpl)6 PageSource (lucee.runtime.PageSource)5 Casting (lucee.runtime.interpreter.ref.cast.Casting)5 ArrayImpl (lucee.runtime.type.ArrayImpl)5