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 11533x 11533x 11533x 11533x 11533x 1x 1x 1215735x 370416x 370416x 370416x 1215735x 1215735x 1x 1x 373163x 373163x 1x 1x 862585x 862585x 1x 1x 370416x 370416x 370416x 370416x 1x 1x 2977x 2977x 18759x 6021x 6021x 18759x 2977x 2977x 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;
}
}
|