Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 15147x 15147x 15147x 15147x 15147x 1x 1x 4587648x 1298143x 1298143x 1298143x 4587648x 4587648x 1x 1x 1300929x 1300929x 1x 1x 3324812x 3324812x 1x 1x 1298143x 1298143x 1298143x 1298143x 1x 1x 3628x 3628x 21852x 7323x 7323x 21852x 3628x 3628x 1x | // The buffer holds a reference to the raw input and tracks the [start, end)
// offset range of the current token, so the token string can be sliced out with
// a single substring() instead of being concatenated one character at a time.
export class LexerBuffer {
private readonly raw: string;
private start: number;
private end: number; // exclusive
private empty: boolean;
public constructor(raw: string) {
this.raw = raw;
this.start = 0;
this.end = 0;
this.empty = true;
}
public add(offset: number): void {
if (this.empty === true) {
this.start = offset < 0 ? 0 : offset;
this.empty = false;
}
this.end = offset + 1;
}
public get(): string {
return this.raw.substring(this.start, this.end);
}
public length(): number {
return this.end - this.start;
}
public clear(): void {
this.start = 0;
this.end = 0;
this.empty = true;
}
public countIsEven(char: number): boolean {
let count = 0;
for (let i = this.start; i < this.end; i += 1) {
if (this.raw.charCodeAt(i) === char) {
count += 1;
}
}
return count % 2 === 0;
}
}
|