Skip to content

Commit e2327f0

Browse files
committed
Strip a byte order mark if present
1 parent eeb2e5b commit e2327f0

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/fallback.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,13 @@ impl FromStr for TokenStream {
182182

183183
fn from_str(src: &str) -> Result<TokenStream, LexError> {
184184
// Create a dummy file & add it to the source map
185-
let cursor = get_cursor(src);
185+
let mut cursor = get_cursor(src);
186+
187+
// Strip a byte order mark if present
188+
const BYTE_ORDER_MARK: &str = "\u{feff}";
189+
if cursor.starts_with(BYTE_ORDER_MARK) {
190+
cursor = cursor.advance(BYTE_ORDER_MARK.len());
191+
}
186192

187193
parse::token_stream(cursor)
188194
}

src/parse.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub(crate) struct Cursor<'a> {
1414
}
1515

1616
impl<'a> Cursor<'a> {
17-
fn advance(&self, bytes: usize) -> Cursor<'a> {
17+
pub fn advance(&self, bytes: usize) -> Cursor<'a> {
1818
let (_front, rest) = self.rest.split_at(bytes);
1919
Cursor {
2020
rest,
@@ -23,7 +23,7 @@ impl<'a> Cursor<'a> {
2323
}
2424
}
2525

26-
fn starts_with(&self, s: &str) -> bool {
26+
pub fn starts_with(&self, s: &str) -> bool {
2727
self.rest.starts_with(s)
2828
}
2929

0 commit comments

Comments
 (0)