rust-cssparser icon indicating copy to clipboard operation
rust-cssparser copied to clipboard

Add ParserState method to get current utf16 position

Open nchevobbe opened this issue 1 year ago • 1 comments

This adds a utf16_position method on ParserState, exposing a current_position field that we compute. The implementation is closely following what what done to compute the utf16 column position.

Note that this is my first contribution here and that I'm not very familiar with Rust.


Motivation: I'm currently building a css tokenizer for Firefox DevTools based on cssparser, replacing an existing JS-based implementation (https://bugzilla.mozilla.org/show_bug.cgi?id=1410184) so we can 1. use the same code than the CSS engine and 2. be faster. Consumers of those tokens are expecting utf16 start and end position for each tokens so the original can easily be manipulated in JS.

nchevobbe avatar Mar 26 '24 06:03 nchevobbe

In any case, current_position and position shouldn't really be subtly in different units. Let's document that if we need it.

emilio avatar Mar 26 '24 10:03 emilio