@solvprotocol/upgrade-safe-transpiler
Version:
Solidity preprocessor used to generate OpenZeppelin Contracts Upgrade Safe.
36 lines • 1.29 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.matchBufferAt = exports.matchBufferFrom = exports.matchBuffer = void 0;
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 => Buffer.from(c, 'utf8').length);
return { start, length, captureLengths };
}
}
function matchBuffer(buf, re) {
return matchWithFlags(buf, re, 0, '');
}
exports.matchBuffer = matchBuffer;
function matchBufferFrom(buf, re, index) {
return matchWithFlags(buf, re, index, 'g');
}
exports.matchBufferFrom = matchBufferFrom;
function matchBufferAt(buf, re, index) {
return matchWithFlags(buf, re, index, 'y');
}
exports.matchBufferAt = matchBufferAt;
//# sourceMappingURL=match.js.map