libsyntax: librustdoc: ignore utf-8 BOM in .rs files

Closes #12974
This commit is contained in:
Liigo Zhuang
2014-03-18 08:59:44 +08:00
committed by Alex Crichton
parent 8f7a7970f3
commit 20e178c582
3 changed files with 31 additions and 2 deletions

View File

@@ -463,6 +463,13 @@ impl<'a> SourceCollector<'a> {
};
let contents = str::from_utf8_owned(contents).unwrap();
// Remove the utf-8 BOM if any
let contents = if contents.starts_with("\ufeff") {
contents.as_slice().slice_from(3)
} else {
contents.as_slice()
};
// Create the intermediate directories
let mut cur = self.dst.clone();
let mut root_path = ~"../../";
@@ -482,7 +489,7 @@ impl<'a> SourceCollector<'a> {
root_path: root_path,
};
try!(layout::render(&mut w as &mut Writer, &self.cx.layout,
&page, &(""), &Source(contents.as_slice())));
&page, &(""), &Source(contents)));
try!(w.flush());
return Ok(());
}