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);
}
}
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 + "]");
}
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);
}
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;
}
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();
}
Aggregations