protected abstract Value evalVar(EvalContext ctx, Value[] params);
}
+ public static class StringFuncWrapper implements Function
+ {
+ private final String _name;
+ private final Function _delegate;
+
+ public StringFuncWrapper(Function delegate) {
+ _delegate = delegate;
+ _name = _delegate.getName() + NON_VAR_SUFFIX;
+ }
+
+ public String getName() {
+ return _name;
+ }
+
+ public boolean isPure() {
+ return _delegate.isPure();
+ }
+
+ public Value eval(EvalContext ctx, Value... params) {
+ Value result = _delegate.eval(ctx, params);
+ if(result.isNull()) {
+ // non-variant version does not do null-propagation, so force
+ // exception to be thrown here
+ result.getAsString();
+ }
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return getName() + "()";
+ }
+ }
+
public static final Function IIF = registerFunc(new Func3("IIf") {
@Override
}
static Function registerStringFunc(Function func) {
- // for our purposes the non-variant versions are the same function
- // (e.g. "Foo" and "Foo$")
registerFunc(func.getName(), func);
- registerFunc(func.getName() + NON_VAR_SUFFIX, func);
+ registerFunc(new StringFuncWrapper(func));
return func;
}
}
});
- public static final Function CHR = registerStringFunc(new Func1("Chr") {
+ public static final Function CHR = registerStringFunc(new Func1NullIsNull("Chr") {
@Override
protected Value eval1(EvalContext ctx, Value param1) {
int lv = param1.getAsLongInt();
}
});
- public static final Function CHRW = registerStringFunc(new Func1("ChrW") {
+ public static final Function CHRW = registerStringFunc(new Func1NullIsNull("ChrW") {
@Override
protected Value eval1(EvalContext ctx, Value param1) {
int lv = param1.getAsLongInt();
}
});
- public static final Function STR = registerStringFunc(new Func1("Str") {
+ public static final Function STR = registerStringFunc(new Func1NullIsNull("Str") {
@Override
protected Value eval1(EvalContext ctx, Value param1) {
BigDecimal bd = param1.getAsBigDecimal();
assertEquals("23072", eval("=Oct(9786)"));
assertEquals(" 9786", eval("=Str(9786)"));
assertEquals("-42", eval("=Str(-42)"));
+ assertEquals("-42", eval("=Str$(-42)"));
+ assertNull(eval("=Str(Null)"));
+
+ try {
+ eval("=Str$(Null)");
+ fail("UnsupportedOperationException should have been thrown");
+ } catch(UnsupportedOperationException expected) {
+ // success
+ }
assertEquals(-1, eval("=CBool(\"1\")"));
assertEquals(13, eval("=CByte(\"13\")"));