Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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