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 | 73d845cbe26df2fb188e30853efb8ce4b0556afe (patch) | |
| tree | 0fd588dfe7d97f616a01118c19ec664c5671d076 /lib/Format/Format.cpp | |
| parent | e4814134df9918ad1414d6f4c6308e0ec0e2fcd2 (diff) | |
| download | clang-73d845cbe26df2fb188e30853efb8ce4b0556afe.tar.gz clang-73d845cbe26df2fb188e30853efb8ce4b0556afe.tar.bz2 clang-73d845cbe26df2fb188e30853efb8ce4b0556afe.tar.xz | |
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
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190519 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/Format.cpp')
| -rw-r--r-- | lib/Format/Format.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 07c6cf974d..52f8b07475 100644 --- a/lib/Format/Format.cpp +++ b/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; |
