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 21675x 21675x 21675x 21675x 21675x 1x 1x 8144865x 2410122x 2410122x 2410122x 8144865x 8144865x 1x 1x 2413644x 2413644x 1x 1x 5762391x 5762391x 1x 1x 2410122x 2410122x 2410122x 2410122x 1x 1x 12376x 12376x 183848x 24840x 24840x 183848x 12376x 12376x 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;
}
}
|