summary refs log tree commit diff
path: root/src/libsyntax/codemap.rs
diff options
context:
space:
mode:
authorLiigo Zhuang <com.liigo@gmail.com>2014-03-18 08:59:44 +0800
committerAlex Crichton <alex@alexcrichton.com>2014-03-18 13:49:11 -0700
commit20e178c5821b32d7a7deab70af90bf50f9d39df3 (patch)
tree4b3a240a0c3f51d46fcf0bc21b1a934b44905e8a /src/libsyntax/codemap.rs
parent8f7a7970f3f01aa2266c6ce3ee031234b86b1b9b (diff)
downloadrust-20e178c5821b32d7a7deab70af90bf50f9d39df3.tar.gz
rust-20e178c5821b32d7a7deab70af90bf50f9d39df3.zip
libsyntax: librustdoc: ignore utf-8 BOM in .rs files
Closes #12974
Diffstat (limited to 'src/libsyntax/codemap.rs')
-rw-r--r--src/libsyntax/codemap.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs
index 4bfd5391a8f..d93b5803eac 100644
--- a/src/libsyntax/codemap.rs
+++ b/src/libsyntax/codemap.rs
@@ -271,13 +271,22 @@ impl CodeMap {
         }
     }
 
-    pub fn new_filemap(&self, filename: FileName, mut src: ~str) -> Rc<FileMap> {
+    pub fn new_filemap(&self, filename: FileName, src: ~str) -> Rc<FileMap> {
         let mut files = self.files.borrow_mut();
         let start_pos = match files.get().last() {
             None => 0,
             Some(last) => last.deref().start_pos.to_uint() + last.deref().src.len(),
         };
 
+        // Remove utf-8 BOM if any.
+        // FIXME #12884: no efficient/safe way to remove from the start of a string
+        // and reuse the allocation.
+        let mut src = if src.starts_with("\ufeff") {
+            src.as_slice().slice_from(3).into_owned()
+        } else {
+            src
+        };
+
         // Append '\n' in case it's not already there.
         // This is a workaround to prevent CodeMap.lookup_filemap_idx from accidentally
         // overflowing into the next filemap in case the last byte of span is also the last