Skip to content
This repository was archived by the owner on May 11, 2023. It is now read-only.

Commit e24f132

Browse files
committed
Fix BOM handling, document TextSize::new
1 parent e99c26c commit e24f132

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

compiler/parser/src/lexer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ where
240240
// spell-checker:ignore feff
241241
if let Some('\u{feff}') = lxr.window[0] {
242242
lxr.window.slide();
243+
lxr.location += '\u{feff}'.text_len();
243244
}
244245
lxr
245246
}

ruff_text_size/src/size.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,15 @@ impl fmt::Debug for TextSize {
3333
}
3434

3535
impl TextSize {
36-
pub const fn from_u32(offset: u32) -> Self {
36+
/// Creates a new `TextSize` at the given `offset`.
37+
///
38+
/// # Examples
39+
///
40+
/// ```rust
41+
/// # use ruff_text_size::*;
42+
/// assert_eq!(TextSize::from(4), TextSize::new(4));
43+
/// ```
44+
pub const fn new(offset: u32) -> Self {
3745
Self { raw: offset}
3846
}
3947

@@ -76,7 +84,7 @@ impl TextSize {
7684
impl From<u32> for TextSize {
7785
#[inline]
7886
fn from(raw: u32) -> Self {
79-
TextSize::from_u32(raw)
87+
TextSize::new(raw)
8088
}
8189
}
8290

0 commit comments

Comments
 (0)