Skip to content

Instantly share code, notes, and snippets.

@yodalee
Created April 26, 2015 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yodalee/4b5d3ee4bf7fe8145464 to your computer and use it in GitHub Desktop.
Save yodalee/4b5d3ee4bf7fe8145464 to your computer and use it in GitHub Desktop.
Discuss the implementation of textdecoder serialize function
fn serialize(mut self, stream: &[u8]) -> &[u8] {
match self.encoding.name() {
"utf-8" | "utf-16be" | "utf-16le" if (!self.ignoreBOM && !self.BOMseen) => {
match stream.get(0) {
Some(token) => {
self.BOMseen = true;
if *token == 0xFEFF {
stream.slice_from(1)
} else {
stream
}
},
None => stream
}
},
_ => stream
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment