UNPKG

@abaplint/runtime

Version:
70 lines 1.95 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.cp = cp; const types_1 = require("../types"); function escapeRegExpCharacter(input) { return input.replace(/[\\^$.*+?()[\]{}|]/g, "\\$&"); } function cp(left, right) { let l = ""; if (typeof left === "number" || typeof left === "string") { l = left.toString(); } else if (left instanceof types_1.Structure) { l = left.getCharacter(); } else if (left instanceof types_1.FieldSymbol) { if (left.getPointer() === undefined) { throw new Error("GETWA_NOT_ASSIGNED"); } return cp(left.getPointer(), right); } else if (left instanceof types_1.Character) { l = left.getTrimEnd(); } else { l = left.get().toString(); } let r = ""; if (typeof right === "string") { r = right.toString(); } else if (right instanceof types_1.Character) { r = right.getTrimEnd(); } else { r = right.get().toString().trimEnd(); } let pattern = ""; for (let i = 0; i < r.length; i++) { const current = r[i]; if (current === "#") { if (i + 1 < r.length) { const next = r[i + 1]; if (next === "#") { pattern += "#"; i++; } else { pattern += escapeRegExpCharacter(next); i++; } } else { pattern += "#"; } } else if (current === "*") { pattern += "[\\s\\S]*"; } else if (current === "+") { pattern += "[\\s\\S]"; } else { pattern += escapeRegExpCharacter(current); } } const reg = new RegExp("^" + pattern + "$", "iu"); return l.match(reg) !== null; } //# sourceMappingURL=cp.js.map