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 11317x 11317x 11317x 11317x 11317x 1x 1x 1190339x 363959x 363959x 363959x 1190339x 1190339x 1x 1x 366697x 366697x 1x 1x 843205x 843205x 1x 1x 363959x 363959x 363959x 363959x 1x 1x 2934x 2934x 18472x 5935x 5935x 18472x 2934x 2934x 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;
}
}
|