rtf-stream-parser
Version:
Stream Transform class to tokenize RTF, and another to de-encapsulate text or HTML
40 lines (39 loc) • 1.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleUnicodeSkip = void 0;
const allTokenHandler = (globals, token) => {
switch (token.type) {
case 0:
case 1:
globals._skip = 0;
break;
case 2:
if (globals._skip > 0) {
globals._skip--;
return true;
}
break;
case 3:
if (globals._skip >= token.data.length) {
globals._skip -= token.data.length;
return true;
}
if (globals._skip > 0) {
token.data = token.data.slice(globals._skip);
globals._skip = 0;
}
break;
}
};
const unicodeSkipControlHandlers = {
uc: (global, token) => {
global._state.uc = token.param || 0;
},
u: global => {
global._skip = global._state.uc;
}
};
exports.handleUnicodeSkip = {
allTokenHandler: allTokenHandler,
controlHandlers: unicodeSkipControlHandlers,
};