Skip to content

Commit

Permalink
Strip a byte order mark if present
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Sep 29, 2022
1 parent eeb2e5b commit e2327f0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,13 @@ impl FromStr for TokenStream {

fn from_str(src: &str) -> Result<TokenStream, LexError> {
// Create a dummy file & add it to the source map
let cursor = get_cursor(src);
let mut cursor = get_cursor(src);

// Strip a byte order mark if present
const BYTE_ORDER_MARK: &str = "\u{feff}";
if cursor.starts_with(BYTE_ORDER_MARK) {
cursor = cursor.advance(BYTE_ORDER_MARK.len());
}

parse::token_stream(cursor)
}
Expand Down
4 changes: 2 additions & 2 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub(crate) struct Cursor<'a> {
}

impl<'a> Cursor<'a> {
fn advance(&self, bytes: usize) -> Cursor<'a> {
pub fn advance(&self, bytes: usize) -> Cursor<'a> {
let (_front, rest) = self.rest.split_at(bytes);
Cursor {
rest,
Expand All @@ -23,7 +23,7 @@ impl<'a> Cursor<'a> {
}
}

fn starts_with(&self, s: &str) -> bool {
pub fn starts_with(&self, s: &str) -> bool {
self.rest.starts_with(s)
}

Expand Down

0 comments on commit e2327f0

Please sign in to comment.