Skip to content

Commit 89476cf

Browse files
author
bors-servo
authored
Auto merge of #249 - servo:position-byte-index, r=jdm
Expose byte index in tokenizer's position. I need it to finish my implementation of Properties and Values syntax. It works on bytes rather than CSS tokens, but it calls the consume a name algorithm, for which I'm using cssparser. However I need to know how much of the input was actually consumed after consuming a name to continue the parse. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-cssparser/249) <!-- Reviewable:end -->
2 parents 48c72da + 6649a8f commit 89476cf

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cssparser"
3-
version = "0.25.5"
3+
version = "0.25.6"
44
authors = [ "Simon Sapin <simon.sapin@exyr.org>" ]
55

66
description = "Rust implementation of CSS Syntax Level 3"

src/tokenizer.rs

+8
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,14 @@ impl<'a> Tokenizer<'a> {
520520
#[derive(PartialEq, Eq, PartialOrd, Ord, Debug, Clone, Copy)]
521521
pub struct SourcePosition(pub(crate) usize);
522522

523+
impl SourcePosition {
524+
/// Returns the current byte index in the original input.
525+
#[inline]
526+
pub fn byte_index(&self) -> usize {
527+
self.0
528+
}
529+
}
530+
523531
/// The line and column number for a given position within the input.
524532
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
525533
pub struct SourceLocation {

0 commit comments

Comments
 (0)