ifc-expressions
Version:
Parsing and evaluation of IFC expressions
33 lines (32 loc) • 1.27 kB
JavaScript
import { Func } from "../Func.js";
import { FuncArgString } from "../arg/FuncArgString.js";
import { ExprEvalSuccessObj } from "../../ExprEvalResult.js";
import { StringValue } from "../../../value/StringValue.js";
import { Type } from "../../../type/Types.js";
import { FuncArgNumeric } from "../arg/FuncArgNumeric.js";
export class SUBSTRING extends Func {
constructor() {
super("SUBSTRING", [
new FuncArgString(true, "input"),
new FuncArgNumeric(true, "fromIncl"),
new FuncArgNumeric(false, "toExcl"),
]);
}
calculateResult(callingExpr, evaluatedArguments) {
const inputString = evaluatedArguments.get("input").getValue();
const fromIncl = evaluatedArguments.get("fromIncl").getValue();
let result;
if (evaluatedArguments.has("toExcl")) {
const toExcl = evaluatedArguments.get("toExcl").getValue();
result = inputString.substring(fromIncl.toNumber(), toExcl.toNumber());
}
else {
result = inputString.substring(fromIncl.toNumber());
}
return new ExprEvalSuccessObj(StringValue.of(result));
}
getReturnType(argumentTypes) {
return Type.STRING;
}
}
//# sourceMappingURL=SUBSTRING.js.map