diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2010-11-18 12:46:39 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2010-11-18 12:46:39 +0000 |
commit | 5a3f1cfafdf49fdc390dc3ffa4982c4024ae24c0 (patch) | |
tree | 12d48b46466dbfd235c1d83f003472ae6d0011c8 /clang/lib/Basic/SourceManager.cpp | |
parent | 9bc166ac861bc15c36c39a9a014a07f3d8c36061 (diff) | |
download | bcm5719-llvm-5a3f1cfafdf49fdc390dc3ffa4982c4024ae24c0.tar.gz bcm5719-llvm-5a3f1cfafdf49fdc390dc3ffa4982c4024ae24c0.zip |
Fix a typo in the UTF-8 BOM (PR8645). Use a StringSwitch while at it.
llvm-svn: 119698
Diffstat (limited to 'clang/lib/Basic/SourceManager.cpp')
-rw-r--r-- | clang/lib/Basic/SourceManager.cpp | 39 |
1 files changed, 15 insertions, 24 deletions
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index 97af0d6fe36..e576b8dc6a2 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -15,6 +15,7 @@ #include "clang/Basic/SourceManagerInternals.h" #include "clang/Basic/Diagnostic.h" #include "clang/Basic/FileManager.h" +#include "llvm/ADT/StringSwitch.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/raw_ostream.h" @@ -131,30 +132,20 @@ const llvm::MemoryBuffer *ContentCache::getBuffer(Diagnostic &Diag, // http://en.wikipedia.org/wiki/Byte_order_mark for more information. if (!isBufferInvalid()) { llvm::StringRef BufStr = Buffer.getPointer()->getBuffer(); - const char *BOM = 0; - if (BufStr.startswith("\xFE\xBB\xBF")) - BOM = "UTF-8"; - else if (BufStr.startswith("\xFE\xFF")) - BOM = "UTF-16 (BE)"; - else if (BufStr.startswith("\xFF\xFE")) - BOM = "UTF-16 (LE)"; - else if (BufStr.startswith(llvm::StringRef("\x00\x00\xFE\xFF", 4))) - BOM = "UTF-32 (BE)"; - else if (BufStr.startswith(llvm::StringRef("\xFF\xFE\x00\x00", 4))) - BOM = "UTF-32 (LE)"; - else if (BufStr.startswith("\x2B\x2F\x76")) - BOM = "UTF-7"; - else if (BufStr.startswith("\xF7\x64\x4C")) - BOM = "UTF-1"; - else if (BufStr.startswith("\xDD\x73\x66\x73")) - BOM = "UTF-EBCDIC"; - else if (BufStr.startswith("\x0E\xFE\xFF")) - BOM = "SDSU"; - else if (BufStr.startswith("\xFB\xEE\x28")) - BOM = "BOCU-1"; - else if (BufStr.startswith("\x84\x31\x95\x33")) - BOM = "BOCU-1"; - + const char *BOM = llvm::StringSwitch<const char *>(BufStr) + .StartsWith("\xEF\xBB\xBF", "UTF-8") + .StartsWith("\xFE\xFF", "UTF-16 (BE)") + .StartsWith("\xFF\xFE", "UTF-16 (LE)") + .StartsWith("\x00\x00\xFE\xFF", "UTF-32 (BE)") + .StartsWith("\xFF\xFE\x00\x00", "UTF-32 (LE)") + .StartsWith("\x2B\x2F\x76", "UTF-7") + .StartsWith("\xF7\x64\x4C", "UTF-1") + .StartsWith("\xDD\x73\x66\x73", "UTF-EBCDIC") + .StartsWith("\x0E\xFE\xFF", "SDSU") + .StartsWith("\xFB\xEE\x28", "BOCU-1") + .StartsWith("\x84\x31\x95\x33", "GB-18030") + .Default(0); + if (BOM) { Diag.Report(FullSourceLoc(Loc, SM), diag::err_unsupported_bom) << BOM << Entry->getName(); |