aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Basic/SourceManager.cpp
diff options
context:
space:
mode:
authorEric Christopher <echristo@apple.com>2011-04-09 00:01:04 +0000
committerEric Christopher <echristo@apple.com>2011-04-09 00:01:04 +0000
commit7f36a79ee9387b738b83a265d6b30427de35b2df (patch)
tree2b640c03ebfd6ed49704afec40858e9dd50f9617 /clang/lib/Basic/SourceManager.cpp
parent143ed0fc72a060f03e4d557e7150f54478fac386 (diff)
downloadllvm-7f36a79ee9387b738b83a265d6b30427de35b2df.zip
llvm-7f36a79ee9387b738b83a265d6b30427de35b2df.tar.gz
llvm-7f36a79ee9387b738b83a265d6b30427de35b2df.tar.bz2
Eat the UTF-8 BOM at the beginning of a file since it's ignored anyhow.
Nom Nom Nom. Patch by Anton Korobeynikov! llvm-svn: 129174
Diffstat (limited to 'clang/lib/Basic/SourceManager.cpp')
-rw-r--r--clang/lib/Basic/SourceManager.cpp11
1 files changed, 5 insertions, 6 deletions
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp
index b6939ec..8262feb 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -126,13 +126,12 @@ const llvm::MemoryBuffer *ContentCache::getBuffer(Diagnostic &Diag,
if (Invalid) *Invalid = true;
return Buffer.getPointer();
}
-
+
// If the buffer is valid, check to see if it has a UTF Byte Order Mark
- // (BOM). We only support UTF-8 without a BOM right now. See
+ // (BOM). We only support UTF-8 with and without a BOM right now. See
// http://en.wikipedia.org/wiki/Byte_order_mark for more information.
llvm::StringRef BufStr = Buffer.getPointer()->getBuffer();
- const char *BOM = llvm::StringSwitch<const char *>(BufStr)
- .StartsWith("\xEF\xBB\xBF", "UTF-8")
+ const char *InvalidBOM = llvm::StringSwitch<const char *>(BufStr)
.StartsWith("\xFE\xFF", "UTF-16 (BE)")
.StartsWith("\xFF\xFE", "UTF-16 (LE)")
.StartsWith("\x00\x00\xFE\xFF", "UTF-32 (BE)")
@@ -145,9 +144,9 @@ const llvm::MemoryBuffer *ContentCache::getBuffer(Diagnostic &Diag,
.StartsWith("\x84\x31\x95\x33", "GB-18030")
.Default(0);
- if (BOM) {
+ if (InvalidBOM) {
Diag.Report(Loc, diag::err_unsupported_bom)
- << BOM << ContentsEntry->getName();
+ << InvalidBOM << ContentsEntry->getName();
Buffer.setInt(Buffer.getInt() | InvalidFlag);
}