diff options
author | Alexander Kornienko <alexfh@google.com> | 2013-09-11 12:25:57 +0000 |
---|---|---|
committer | Alexander Kornienko <alexfh@google.com> | 2013-09-11 12:25:57 +0000 |
commit | 9e649af004b2033c6dd802c80fc1b889f066c9ad (patch) | |
tree | fe5fa4091a1df2c5f7c97b48b56bfd5d044134ca /clang/lib/Format/Format.cpp | |
parent | fbcb5829420eae3777de7c7990327ce0b5505de4 (diff) | |
download | bcm5719-llvm-9e649af004b2033c6dd802c80fc1b889f066c9ad.tar.gz bcm5719-llvm-9e649af004b2033c6dd802c80fc1b889f066c9ad.zip |
Support for CR LF newlines.
Summary:
reformat() tries to determine the newline style used in the input
(either LF or CR LF), and uses it for the output. Maybe not every single case is
supported, but at least the bug described in http://llvm.org/PR17182 should be
resolved.
Reviewers: djasper
Reviewed By: djasper
CC: cfe-commits, klimek
Differential Revision: http://llvm-reviews.chandlerc.com/D1643
llvm-svn: 190519
Diffstat (limited to 'clang/lib/Format/Format.cpp')
-rw-r--r-- | clang/lib/Format/Format.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 07c6cf974da..52f8b07475d 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -631,7 +631,9 @@ private: ++FormatTok->NewlinesBefore; // FIXME: This is technically incorrect, as it could also // be a literal backslash at the end of the line. - if (i == 0 || FormatTok->TokenText[i - 1] != '\\') + if (i == 0 || (FormatTok->TokenText[i - 1] != '\\' && + (FormatTok->TokenText[i - 1] != '\r' || i == 1 || + FormatTok->TokenText[i - 2] != '\\'))) FormatTok->HasUnescapedNewline = true; FormatTok->LastNewlineOffset = WhitespaceLength + i + 1; Column = 0; @@ -745,8 +747,8 @@ public: Formatter(const FormatStyle &Style, Lexer &Lex, SourceManager &SourceMgr, const std::vector<CharSourceRange> &Ranges) : Style(Style), Lex(Lex), SourceMgr(SourceMgr), - Whitespaces(SourceMgr, Style), Ranges(Ranges), - Encoding(encoding::detectEncoding(Lex.getBuffer())) { + Whitespaces(SourceMgr, Style, inputUsesCRLF(Lex.getBuffer())), + Ranges(Ranges), Encoding(encoding::detectEncoding(Lex.getBuffer())) { DEBUG(llvm::dbgs() << "File encoding: " << (Encoding == encoding::Encoding_UTF8 ? "UTF8" : "unknown") @@ -883,6 +885,10 @@ public: } private: + static bool inputUsesCRLF(StringRef Text) { + return Text.count('\r') * 2 > Text.count('\n'); + } + void deriveLocalStyle() { unsigned CountBoundToVariable = 0; unsigned CountBoundToType = 0; |