AdvanceN moves the position forward by n bytes and recalculates the line and column numbers using the provided line start indices. This is used when jumping forward in the input (e.g., after skipping a comment block) where individual rune tracking would be inefficient. Parameters: - n: Number of b
(n int, lineStarts []int)
| 118 | // |
| 119 | // If n <= 0, this is a no-op. |
| 120 | func (p *Position) AdvanceN(n int, lineStarts []int) { |
| 121 | if n <= 0 { |
| 122 | return |
| 123 | } |
| 124 | |
| 125 | // Update index |
| 126 | p.Index += n |
| 127 | |
| 128 | // Find which line we're on |
| 129 | for i := len(lineStarts) - 1; i >= 0; i-- { |
| 130 | if p.Index >= lineStarts[i] { |
| 131 | p.Line = i + 1 |
| 132 | p.Column = p.Index - lineStarts[i] + 1 |
| 133 | break |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | // Clone creates a copy of this Position. |
| 139 | // The returned Position is independent and can be modified without |
no outgoing calls