Public
Edited
Jul 13, 2023
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
extracts = {
const s = OP2CH("save");
const r = OP2CH("restore");
const re = new RegExp(`${s}.*?${r}`, 'g');

const strToIndex = new Map();
const extracts = [];

let breakout = 0;
re.lastIndex = 0;
for (;;) {
if (++breakout > 1000) break;

const match = re.exec(pdf.str);
if (!match) break;

const str = match[0];
if (strToIndex.has(str)) {
++extracts[strToIndex.get(str)].count;
continue;
}
strToIndex.set(str, extracts.length);

const extract = EXTRACT(match.index, re.lastIndex);
extracts.push({ str, extract, count: 1 });
}

return extracts;
function OP2CH(op) {
const fn = pdf.mapOpToFn.get(op);
const ch = pdf.mapFnToCh.get(fn);
return ch;
}

function EXTRACT(startIndex, endIndex) {
const extract = [];
for (let i=startIndex, n=endIndex; i<n; ++i) {
const op = pdf.ops[i];
const arg = pdf.arg[i];
extract.push({ op, arg });
}
return extract;
}
}
Insert cell
import {inspect} from "@observablehq/inspector"
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more