Position returns line and column number of given index of the original input. It will panic if index is out of range.
(idx int)
| 223 | // Position returns line and column number of given index of the original input. |
| 224 | // It will panic if index is out of range. |
| 225 | func (d *Decoder) Position(idx int) (line int, column int) { |
| 226 | b := d.orig[:idx] |
| 227 | line = bytes.Count(b, []byte("\n")) + 1 |
| 228 | if i := bytes.LastIndexByte(b, '\n'); i >= 0 { |
| 229 | b = b[i+1:] |
| 230 | } |
| 231 | column = utf8.RuneCount(b) + 1 // ignore multi-rune characters |
| 232 | return line, column |
| 233 | } |
| 234 | |
| 235 | // currPos returns the current index position of d.in from d.orig. |
| 236 | func (d *Decoder) currPos() int { |
no outgoing calls
no test coverage detected