Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ParserState method to get current utf16 position #374

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

nchevobbe
Copy link

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.

src/tokenizer.rs Outdated Show resolved Hide resolved
@emilio
Copy link
Member

emilio commented Mar 26, 2024

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

@nchevobbe nchevobbe requested a review from emilio April 10, 2024 15:46
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants