char-info
Version:
Unicode character information library.
40 lines • 1.34 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BasicCharClassIndicator = void 0;
function binarySearchInIntervals(intervals) {
return function bin(start, end, char) {
if (start > end) {
return false;
}
const mid = (start + end) >> 1;
const midInterval = intervals[mid];
if (midInterval.low > char) {
return bin(start, mid - 1, char);
}
if (midInterval.high < char) {
return bin(mid + 1, end, char);
}
return true;
};
}
/** Basic implementation for the CharClassIndicator, using binary search in an array of ranges. */
class BasicCharClassIndicator {
constructor(_group) {
this._group = _group;
const intervals = _group.intervals;
this._binarySearchInIntervals = binarySearchInIntervals(intervals);
this.char = this.char.bind(this);
this.code = this.code.bind(this);
}
code(char) {
const intervals = this._group.intervals;
return this._binarySearchInIntervals(0, intervals.length - 1, char);
}
char(char) {
if (char === "")
return false;
return this.code(char.codePointAt(0));
}
}
exports.BasicCharClassIndicator = BasicCharClassIndicator;
//# sourceMappingURL=indicators.js.map