public:
FormatTokenLexer(Lexer &Lex, SourceManager &SourceMgr, FormatStyle &Style,
encoding::Encoding Encoding)
- : FormatTok(NULL), GreaterStashed(false), Column(0),
+ : FormatTok(NULL), IsFirstToken(true), GreaterStashed(false), Column(0),
TrailingWhitespace(0), Lex(Lex), SourceMgr(SourceMgr), Style(Style),
IdentTable(getFormattingLangOpts()), Encoding(Encoding) {
Lex.SetKeepWhitespaceMode(true);
readRawToken(*FormatTok);
SourceLocation WhitespaceStart =
FormatTok->Tok.getLocation().getLocWithOffset(-TrailingWhitespace);
- if (SourceMgr.getFileOffset(WhitespaceStart) == 0)
- FormatTok->IsFirst = true;
+ FormatTok->IsFirst = IsFirstToken;
+ IsFirstToken = false;
// Consume and record whitespace until we find a significant token.
unsigned WhitespaceLength = TrailingWhitespace;
}
FormatToken *FormatTok;
+ bool IsFirstToken;
bool GreaterStashed;
unsigned Column;
unsigned TrailingWhitespace;
getLLVMStyleWithColumns(12)));
}
+TEST_F(FormatTest, HandlesUTF8BOM) {
+ EXPECT_EQ("\xef\xbb\xbf", format("\xef\xbb\xbf"));
+ EXPECT_EQ("\xef\xbb\xbf#include <iostream>",
+ format("\xef\xbb\xbf#include <iostream>"));
+ EXPECT_EQ("\xef\xbb\xbf\n#include <iostream>",
+ format("\xef\xbb\xbf\n#include <iostream>"));
+}
+
// FIXME: Encode Cyrillic and CJK characters below to appease MS compilers.
#if !defined(_MSC_VER)