jsonc-parser icon indicating copy to clipboard operation
jsonc-parser copied to clipboard

common::Ranged provides method to convert to line/col from byte index

Open kitsonk opened this issue 2 years ago • 2 comments

Like Ranged::text(), taking the original text, it would be great to be able to return a (usize, usize) that returns a line and column variant, which is more used when displaying positions to users or editors.

kitsonk avatar Jul 29 '22 03:07 kitsonk

That sounds good! Probably would just do a simple iteration of all the chars leading up to the position each time to compute this.

By the way, another possibility might be to use text_lines for this. It’s already in the CLI https://github.com/dsherret/text_lines

dsherret avatar Jul 29 '22 03:07 dsherret

The ParseResult could contain the line index (as an parse option) which would make it easy to coerce into a line/col.

kitsonk avatar Jul 29 '22 03:07 kitsonk