@openzeppelin/upgrade-safe-transpiler
Version:
Solidity preprocessor used to generate OpenZeppelin Contracts Upgrade Safe.
37 lines • 1.26 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.matchBuffer = matchBuffer;
exports.matchBufferFrom = matchBufferFrom;
exports.matchBufferAt = matchBufferAt;
function withFlags(re, add, remove = '') {
const flags = new Set(...re.flags);
for (const f of add) {
flags.add(f);
}
for (const f of remove) {
flags.delete(f);
}
return new RegExp(re, [...flags].join(''));
}
function matchWithFlags(buf, re, index, flags) {
const str = buf.slice(index).toString('utf8');
const m = withFlags(re, flags).exec(str);
if (m) {
const start = index + Buffer.from(str.slice(0, m.index), 'utf8').length;
const length = Buffer.from(str.slice(m.index, m.index + m[0].length), 'utf8').length;
const captureLengths = m
.slice(1)
.map(c => (c === undefined ? c : Buffer.from(c, 'utf8').length));
return { start, length, captureLengths };
}
}
function matchBuffer(buf, re) {
return matchWithFlags(buf, re, 0, '');
}
function matchBufferFrom(buf, re, index) {
return matchWithFlags(buf, re, index, 'g');
}
function matchBufferAt(buf, re, index) {
return matchWithFlags(buf, re, index, 'y');
}
//# sourceMappingURL=match.js.map