ifc-expressions
Version:
Parsing and evaluation of IFC expressions
47 lines (46 loc) • 2.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MatchesPattern = void 0;
const ApplyRegex_js_1 = require("./ApplyRegex.js");
const ExprEvalResult_js_1 = require("../../ExprEvalResult.js");
const BooleanValue_js_1 = require("../../../value/BooleanValue.js");
const IfcExpressionUtils_js_1 = require("../../../util/IfcExpressionUtils.js");
const Types_js_1 = require("../../../type/Types.js");
class MatchesPattern extends ApplyRegex_js_1.ApplyRegex {
constructor(name, simplePattern, requireFullMatch) {
super(name, simplePattern, requireFullMatch);
}
getReturnType(argumentTypes) {
return Types_js_1.Type.BOOLEAN;
}
calculateResult(callingExpr, evaluatedArguments) {
const inputValue = evaluatedArguments.get(MatchesPattern.KEY_INPUT);
const patternValue = evaluatedArguments.get(MatchesPattern.KEY_PATTERN);
const pattern = patternValue.getValue();
if (pattern.length === 0) {
return new ExprEvalResult_js_1.ExprEvalSuccessObj(BooleanValue_js_1.BooleanValue.of(false));
}
let flags = "m"; // default for simple pattern
if (this.simplePattern) {
const caseSensitive = evaluatedArguments.get(MatchesPattern.KEY_CASE_INSENSITIVE);
if (caseSensitive) {
flags = "im";
}
}
else {
flags = evaluatedArguments.get(MatchesPattern.KEY_FLAGS).getValue();
}
const regex = new RegExp(pattern, flags);
const input = inputValue.getValue();
const matches = input.match(regex);
if ((0, IfcExpressionUtils_js_1.isNullish)(matches)) {
return new ExprEvalResult_js_1.ExprEvalSuccessObj(BooleanValue_js_1.BooleanValue.of(false));
}
if (this.requireFullMatch) {
return new ExprEvalResult_js_1.ExprEvalSuccessObj(BooleanValue_js_1.BooleanValue.of(matches[0] === input));
}
return new ExprEvalResult_js_1.ExprEvalSuccessObj(BooleanValue_js_1.BooleanValue.of(true));
}
}
exports.MatchesPattern = MatchesPattern;
//# sourceMappingURL=MatchesPattern.js.map