updateLineNumber scans only new cached data for newlines to update current line position
()
| 135 | |
| 136 | // updateLineNumber scans only new cached data for newlines to update current line position |
| 137 | func (p *parser) updateLineNumber() { |
| 138 | if p.lineStarts == nil { |
| 139 | return |
| 140 | } |
| 141 | offset := int(p.decoder.InputOffset()) |
| 142 | for i := p.currentLine; i < len(p.lineStarts); i++ { |
| 143 | if offset > p.lineStarts[i] && p.lineStarts[i] >= p.lastProcessedPos { |
| 144 | p.currentLine = i + 1 |
| 145 | break |
| 146 | } |
| 147 | if offset <= p.lineStarts[i] { |
| 148 | break |
| 149 | } |
| 150 | } |
| 151 | p.lastProcessedPos = offset |
| 152 | /* |
| 153 | cached := p.reader.CacheWithLimit(-1) // Get all cached data |
| 154 | |
| 155 | // Only process data we haven't seen before |
| 156 | for i := p.lastProcessedPos; i < len(cached); i++ { |
| 157 | if cached[i] == '\n' { |
| 158 | p.currentLine++ |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | // Update our position to avoid reprocessing this data |
| 163 | p.lastProcessedPos = len(cached) |
| 164 | */ |
| 165 | } |
| 166 | |
| 167 | func (p *parser) parse() (*Node, error) { |
| 168 | p.once.Do(func() { |