Skip to content

Commit

Permalink
use Number instead of double for functions (will break things ;-) )
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Sep 10, 2024
1 parent d86518a commit 3f50a48
Show file tree
Hide file tree
Showing 18 changed files with 59 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public final class ArrayAvg extends BIF {

private static final long serialVersionUID = -6440677638555730262L;

public static double call(PageContext pc, Array array) throws ExpressionException {
public static Number call(PageContext pc, Array array) throws ExpressionException {
return ArrayUtil.avg(array);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public final class ArrayContains extends BIF {

private static final long serialVersionUID = -5400552848978801342L;

public static double call(PageContext pc, Array array, Object value, boolean substringMatch) throws PageException {
public static Number call(PageContext pc, Array array, Object value, boolean substringMatch) throws PageException {
if (substringMatch) {
if (!Decision.isSimpleValue(value))
throw new FunctionException(pc, "ArrayContains", 3, "substringMatch", "substringMatch can not be true when the value that is searched for is a complex object");
Expand All @@ -43,7 +43,7 @@ public static double call(PageContext pc, Array array, Object value, boolean sub
return ArrayFind.call(pc, array, value);
}

public static double call(PageContext pc, Array array, Object value) throws PageException {
public static Number call(PageContext pc, Array array, Object value) throws PageException {
return call(pc, array, value, false);
}

Expand All @@ -55,9 +55,9 @@ public Object invoke(PageContext pc, Object[] args) throws PageException {
}

/* legacy implementation */
static double callLegacy(PageContext pc, Array array, Object value) throws PageException {
static Number callLegacy(PageContext pc, Array array, Object value) throws PageException {
String str = Caster.toString(value, null);
if (str != null) return ArrayUtil.arrayContainsIgnoreEmpty(array, str, false) + 1;
if (str != null) return Caster.toNumber(pc, ArrayUtil.arrayContainsIgnoreEmpty(array, str, false) + 1);
return ArrayFind.call(pc, array, value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ public final class ArrayContainsNoCase extends BIF {

private static final long serialVersionUID = 4394078979692450076L;

public static double call(PageContext pc, Array array, Object value) {
public static Number call(PageContext pc, Array array, Object value) {
return ArrayFindNoCase.call(pc, array, value);
}

public static double call(PageContext pc, Array array, Object value, boolean substringMatch) throws PageException {
public static Number call(PageContext pc, Array array, Object value, boolean substringMatch) throws PageException {
if (substringMatch) {
if (!Decision.isSimpleValue(value)) throw new FunctionException(pc, "ArrayContainsNoCase", 3, "substringMatch",
"substringMatch can not be true when the value that is searched for is a complex object");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,22 @@ public Object invoke(PageContext pc, Object[] args) throws PageException {

static boolean _call(PageContext pc, Array array, Object value, String scope, boolean caseSensitive) throws PageException {
boolean onlyFirst = !"all".equalsIgnoreCase(scope);
double pos;
int pos;
if ((pos = find(pc, array, value, caseSensitive)) > 0) {
array.removeE((int) pos);
array.removeE(pos);
if (onlyFirst) return true;
}
else return false;

while ((pos = find(pc, array, value, caseSensitive)) > 0) {
array.removeE((int) pos);
array.removeE(pos);
}

return true;
}

private static double find(PageContext pc, Array array, Object value, boolean caseSensitive) throws PageException {
return caseSensitive ? ArrayFind.call(pc, array, value) : ArrayFindNoCase.call(pc, array, value);
private static int find(PageContext pc, Array array, Object value, boolean caseSensitive) throws PageException {
return Caster.toIntValue(caseSensitive ? ArrayFind.call(pc, array, value) : ArrayFindNoCase.call(pc, array, value));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ public final class ArrayFind extends BIF {

private static final long serialVersionUID = -3282048672805234115L;

public static double call(PageContext pc, Array array, Object value) throws PageException {
if (value instanceof UDF) return find(pc, array, (UDF) value);
public static Number call(PageContext pc, Array array, Object value) throws PageException {
if (value instanceof UDF) return Caster.toNumber(pc, find(pc, array, (UDF) value));

return find(pc, array, value, true);
return Caster.toNumber(pc, find(pc, array, value, true));
}

@Override
public Object invoke(PageContext pc, Object[] args) throws PageException {
if (args.length == 2) return call(pc, Caster.toArray(args[0]), args[1]);
else throw new FunctionException(pc, "ArrayFind", 2, 2, args.length);
throw new FunctionException(pc, "ArrayFind", 2, 2, args.length);
}

public static int find(PageContext pc, Array array, UDF udf) throws PageException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ public final class ArrayFindNoCase extends BIF {

private static final long serialVersionUID = 3636181944643536992L;

public static double call(PageContext pc, Array array, Object value) {
return ArrayFind.find(pc, array, value, false);
public static Number call(PageContext pc, Array array, Object value) {
return Caster.toNumber(pc, ArrayFind.find(pc, array, value, false));
}

@Override
public Object invoke(PageContext pc, Object[] args) throws PageException {
if (args.length == 2) return call(pc, Caster.toArray(args[0]), args[1]);
else throw new FunctionException(pc, "ArrayFindNoCase", 2, 2, args.length);
throw new FunctionException(pc, "ArrayFindNoCase", 2, 2, args.length);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ public final class ListFindNoCase extends BIF {

private static final long serialVersionUID = 8596474187680730966L;

public static double call(PageContext pc, String list, String value) {
return ListUtil.listFindNoCaseIgnoreEmpty(list, value, ',') + 1;
public static Number call(PageContext pc, String list, String value) {
return Caster.toNumber(pc, ListUtil.listFindNoCaseIgnoreEmpty(list, value, ',') + 1);
}

public static double call(PageContext pc, String list, String value, String delimter) {
return ListUtil.listFindNoCaseIgnoreEmpty(list, value, delimter) + 1;
public static Number call(PageContext pc, String list, String value, String delimter) {
return Caster.toNumber(pc, ListUtil.listFindNoCaseIgnoreEmpty(list, value, delimter) + 1);
}

public static double call(PageContext pc, String list, String value, String delimter, boolean includeEmptyFields) {
if (includeEmptyFields) return ListUtil.listFindNoCase(list, value, delimter) + 1;
return ListUtil.listFindNoCaseIgnoreEmpty(list, value, delimter) + 1;
public static Number call(PageContext pc, String list, String value, String delimter, boolean includeEmptyFields) {
if (includeEmptyFields) return Caster.toNumber(pc, ListUtil.listFindNoCase(list, value, delimter) + 1);
return Caster.toNumber(pc, ListUtil.listFindNoCaseIgnoreEmpty(list, value, delimter) + 1);
}

@Override
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/java/lucee/runtime/functions/other/Dump.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,17 @@ public static String call(PageContext pc, Object object, String label, boolean e
return call(pc, object, label, expand, maxLevel, show, hide, output, format, 9999, true, true);
}

public static String call(PageContext pc, Object object, String label, boolean expand, Number maxLevel, String show, String hide, String output, String format, double keys)
public static String call(PageContext pc, Object object, String label, boolean expand, Number maxLevel, String show, String hide, String output, String format, Number keys)
throws PageException {
return call(pc, object, label, expand, maxLevel, show, hide, output, format, keys, true, true);
}

public static String call(PageContext pc, Object object, String label, boolean expand, Number maxLevel, String show, String hide, String output, String format, double keys,
public static String call(PageContext pc, Object object, String label, boolean expand, Number maxLevel, String show, String hide, String output, String format, Number keys,
boolean metainfo) throws PageException {
return call(pc, object, label, expand, maxLevel, show, hide, output, format, keys, metainfo, true);
}

public static String call(PageContext pc, Object object, String label, boolean expand, Number maxLevel, String show, String hide, String output, String format, double keys,
public static String call(PageContext pc, Object object, String label, boolean expand, Number maxLevel, String show, String hide, String output, String format, Number keys,
boolean metainfo, boolean showUDFs) throws PageException {
if (show != null && "all".equalsIgnoreCase(show.trim())) show = null;
if (hide != null && "all".equalsIgnoreCase(hide.trim())) hide = null;
Expand Down Expand Up @@ -130,7 +130,7 @@ else if ("console".equalsIgnoreCase(output)) {
Set<String> setShow = (show != null) ? ListUtil.listToSet(show.toLowerCase(), ",", true) : null;
Set<String> setHide = (hide != null) ? ListUtil.listToSet(hide.toLowerCase(), ",", true) : null;

DumpProperties properties = new DumpProperties(Caster.toIntValue(maxLevel), setShow, setHide, (int) keys, metainfo, showUDFs);
DumpProperties properties = new DumpProperties(Caster.toIntValue(maxLevel), setShow, setHide, Caster.toIntValue(keys), metainfo, showUDFs);
DumpData dd = DumpUtil.toDumpData(object, pc, Caster.toIntValue(maxLevel), properties);

if (!StringUtil.isEmpty(label)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public final class QueryConvertForGrid extends BIF {

private static final long serialVersionUID = 871091293736619034L;

public static Struct call(PageContext pc, Query src, Number npage, double dpageSize) throws PageException {
public static Struct call(PageContext pc, Query src, Number npage, Number npageSize) throws PageException {
int page = Caster.toIntValue(npage);
int pageSize = (int) dpageSize;
int pageSize = Caster.toIntValue(npageSize);
if (page < 1) {
throw new FunctionException(pc, "QueryConvertForGrid", 2, "page", "page must be a positive number now (" + page + ")");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class QueryRowSwap extends BIF implements Function {

private static final long serialVersionUID = -812740090032092109L;

public static Query call(PageContext pc, Query qry, Number nsource, double destination) throws PageException {
public static Query call(PageContext pc, Query qry, Number nsource, Number ndestination) throws PageException {
// validate source
int source = Caster.toIntValue(nsource);
if (source < 1) throw new FunctionException(pc, "QueryRowSwap", 2, "source", "source most be at least one, now it is [" + Caster.toString(source) + "].");
Expand All @@ -25,11 +25,12 @@ public static Query call(PageContext pc, Query qry, Number nsource, double desti
int src = source;

// validate destination
int destination = Caster.toIntValue(ndestination);
if (destination < 1)
throw new FunctionException(pc, "QueryRowSwap", 3, "destination", "destination most be at least one, now it is [" + Caster.toString(destination) + "].");
if (destination > qry.getRowCount()) throw new FunctionException(pc, "QueryRowSwap", 3, "destination",
"destination [" + Caster.toString(destination) + "] cannot be bigger than recordcount [" + qry.getRecordcount() + "] of the query.");
int dest = (int) destination;
int dest = destination;

Collection.Key[] colNames = qry.getColumnNames();

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/lucee/runtime/functions/string/Asc.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public static Number call(PageContext pc, String string) {
return Caster.toNumber(pc, string.charAt(0));
}

public static Number call(PageContext pc, String string, double position) {
int pos = (int) position;
public static Number call(PageContext pc, String string, Number position) {
int pos = Caster.toIntValue(position);
if (pos < 1 || pos > string.length()) return 0;
return Caster.toNumber(pc, string.charAt(pos - 1));
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/lucee/runtime/functions/string/Chr.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static String call(PageContext pc, Number number) throws ExpressionExcept

@Override
public Object invoke(PageContext pc, Object[] args) throws PageException {
if (args.length == 1) return call(pc, Caster.toDoubleValue(args[0]));
if (args.length == 1) return call(pc, Caster.toNumber(pc, args[0]));
throw new FunctionException(pc, "chr", 1, 1, args.length);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ public final class DayOfWeekShortAsString extends BIF {

private static final long serialVersionUID = 3088890446888229079L;

public static String call(PageContext pc, double dow) throws ExpressionException {
public static String call(PageContext pc, Number dow) throws ExpressionException {
return DayOfWeekAsString.call(pc, dow, pc.getLocale(), false);
}

public static String call(PageContext pc, double dow, Locale locale) throws ExpressionException {
public static String call(PageContext pc, Number dow, Locale locale) throws ExpressionException {
return DayOfWeekAsString.call(pc, dow, locale == null ? pc.getLocale() : locale, false);
}

@Override
public Object invoke(PageContext pc, Object[] args) throws PageException {
if (args.length == 1) return call(pc, Caster.toDoubleValue(args[0]));
if (args.length == 2) return call(pc, Caster.toDoubleValue(args[0]), Caster.toLocale(args[1]));
if (args.length == 1) return call(pc, Caster.toNumber(pc, args[0]));
if (args.length == 2) return call(pc, Caster.toNumber(pc, args[0]), Caster.toLocale(args[1]));
throw new FunctionException(pc, "DayOfWeekShortAsString", 1, 2, args.length);
}
}
4 changes: 2 additions & 2 deletions core/src/main/java/lucee/runtime/functions/string/Len.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ public static Number call(PageContext pc, String string) {
}

public static Number call(PageContext pc, Object obj) throws FunctionException {
double len = invoke(obj, -1);
int len = invoke(obj, -1);
if (len == -1) throw new FunctionException(pc, "len", 1, "object", "this type [" + Caster.toTypeName(obj) + "] is not supported for returning the len");
return Caster.toNumber(pc, len);
}

public static double invoke(Object obj, double defaultValue) {
public static int invoke(Object obj, int defaultValue) {
if (obj instanceof CharSequence) return ((CharSequence) obj).length();
if (obj instanceof Query) return ((Query) obj).getRecordcount();
if (obj instanceof Collection) return ((Collection) obj).size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,27 @@ public static Object call(PageContext pc, String regExpr, String str) throws Pag
return call(pc, regExpr, str, 1, false, null, false);
}

public static Object call(PageContext pc, String regExpr, String str, double start) throws PageException {
public static Object call(PageContext pc, String regExpr, String str, Number start) throws PageException {
return call(pc, regExpr, str, start, false, null, false);
}

public static Object call(PageContext pc, String regExpr, String str, double start, boolean returnsubexpressions) throws PageException {
public static Object call(PageContext pc, String regExpr, String str, Number start, boolean returnsubexpressions) throws PageException {
return call(pc, regExpr, str, start, returnsubexpressions, null, false);
}

public static Object call(PageContext pc, String regExpr, String str, double start, boolean returnsubexpressions, String scope) throws PageException {
public static Object call(PageContext pc, String regExpr, String str, Number start, boolean returnsubexpressions, String scope) throws PageException {
return call(pc, regExpr, str, start, returnsubexpressions, scope, false);
}

public static Object call(PageContext pc, String regExpr, String str, double start, boolean returnsubexpressions, String scope, boolean multiline) throws PageException {
public static Object call(PageContext pc, String regExpr, String str, Number start, boolean returnsubexpressions, String scope, boolean multiline) throws PageException {
Regex regex = ((PageContextImpl) pc).getRegex();
boolean isMatchAll = scope == null ? false : scope.equalsIgnoreCase("all");
if (returnsubexpressions) {
if (isMatchAll) return regex.findAll(regExpr, str, (int) start, false, multiline);
return regex.find(regExpr, str, (int) start, false, multiline);
if (isMatchAll) return regex.findAll(regExpr, str, Caster.toIntValue(start), false, multiline);
return regex.find(regExpr, str, Caster.toIntValue(start), false, multiline);
}
if (isMatchAll) return regex.indexOfAll(regExpr, str, (int) start, false, multiline);
return regex.indexOf(regExpr, str, (int) start, false, multiline);
if (isMatchAll) return regex.indexOfAll(regExpr, str, Caster.toIntValue(start), false, multiline);
return regex.indexOf(regExpr, str, Caster.toIntValue(start), false, multiline);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@
import lucee.runtime.text.xml.XMLUtil;

public final class XmlChildPos implements Function {
public static Number call(PageContext pc, Node node, String name, double index) {
private static final long serialVersionUID = 3974926152573671355L;

public static Number call(PageContext pc, Node node, String name, Number nindex) {

XMLNodeList xmlNodeList = new XMLNodeList(node, false, Node.ELEMENT_NODE);
int len = xmlNodeList.getLength();
// if(index<1)throw new FunctionException(pc,"XmlChildPos","second","index","attribute must be 1 or
// greater");
int count = 1;
int index = Caster.toIntValue(nindex);
for (int i = 0; i < len; i++) {
Node n = xmlNodeList.item(i);
if (XMLUtil.nameEqual(n, name, XMLUtil.isCaseSensitve(n)) && count++ == index) return Caster.toNumber(pc, i + 1);
Expand Down
2 changes: 1 addition & 1 deletion loader/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project default="core" basedir="." name="Lucee"
xmlns:resolver="antlib:org.apache.maven.resolver.ant">

<property name="version" value="6.1.1.81-SNAPSHOT"/>
<property name="version" value="6.1.1.82-SNAPSHOT"/>

<taskdef uri="antlib:org.apache.maven.resolver.ant" resource="org/apache/maven/resolver/ant/antlib.xml">
<classpath>
Expand Down
2 changes: 1 addition & 1 deletion loader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.lucee</groupId>
<artifactId>lucee</artifactId>
<version>6.1.1.81-SNAPSHOT</version>
<version>6.1.1.82-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Lucee Loader Build</name>
Expand Down

0 comments on commit 3f50a48

Please sign in to comment.