| 56 | } |
| 57 | |
| 58 | getLine(line: number): string | undefined { |
| 59 | if (line < 1) return undefined; // Lines are 1-indexed |
| 60 | let currentLine = 1; |
| 61 | let start = 0; |
| 62 | while (currentLine < line && start < this.buffer.length) { |
| 63 | const nextNewline = this.buffer.indexOf('\n', start); |
| 64 | if (nextNewline === -1) break; // No more lines |
| 65 | start = nextNewline + 1; // Move past the newline character |
| 66 | currentLine++; |
| 67 | } |
| 68 | if (currentLine !== line) return undefined; // Line not found |
| 69 | const end = this.buffer.indexOf('\n', start); |
| 70 | if (end === -1) return this.buffer.slice(start); // Last line |
| 71 | return this.buffer.slice(start, end); |
| 72 | } |
| 73 | |
| 74 | error(message: string): never { |
| 75 | const { line, col } = this.lineCol; |