diff options
author | John Dallaway | 2014-08-22 17:50:55 +0000 |
---|---|---|
committer | Sergey Prigogin | 2014-08-22 19:06:45 +0000 |
commit | 3663a18bc813a527cf773e7ff551caa17ccbce04 (patch) | |
tree | 248ebc8d0619493622eef08966fbcfdcf1010d65 | |
parent | 4f6b3c9174e1248e36de0e9a814f3244bd93dc08 (diff) | |
download | org.eclipse.cdt-3663a18bc813a527cf773e7ff551caa17ccbce04.tar.gz org.eclipse.cdt-3663a18bc813a527cf773e7ff551caa17ccbce04.tar.xz org.eclipse.cdt-3663a18bc813a527cf773e7ff551caa17ccbce04.zip |
Bug 442186: Code formatter handling of CRLF after single line comment
Change-Id: I1a17ec992fd881851e076c732629ac912effc2f1
Signed-off-by: John Dallaway <john@dallaway.org.uk>
Reviewed-on: https://git.eclipse.org/r/32024
Tested-by: Hudson CI
Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
Tested-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
2 files changed, 15 insertions, 2 deletions
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/scanner/SimpleScanner.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/scanner/SimpleScanner.java index 448d0f2d5c2..3d3b60cc821 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/scanner/SimpleScanner.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/scanner/SimpleScanner.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2011 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,6 +9,7 @@ * IBM Corporation - initial implementation * Anton Leherbauer - adding tokens for preprocessing directives * Markus Schorn - classification of preprocessing directives. + * John Dallaway - handle CRLF after single line comment (bug 442186) *******************************************************************************/ package org.eclipse.cdt.internal.formatter.scanner; @@ -831,7 +832,13 @@ public class SimpleScanner { private void matchSinglelineComment(boolean includeNewline) { int c = getChar(); while (c != '\n' && c != EOFCHAR) { - c = getChar(); + int next = getChar(); + if (c == '\r' && next == '\n' && !includeNewline) { + // exclude CRLF line ending + ungetChar(next); + break; + } + c = next; } if (c == EOFCHAR || !includeNewline) { ungetChar(c); diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java index 971db070a25..b6cac775e7a 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java @@ -2999,4 +2999,10 @@ public class CodeFormatterTest extends BaseUITestCase { public void testFunctionMacroInInitializerExpression() throws Exception { assertFormatterResult(); } + + public void testCrLfAfterSingleLineComment_Bug442186() throws Exception { + String before = "#define TESTING1 //\r\n#define TESTING2 // CR \r in comment\r\n"; + String expected = before; + assertFormatterResult(before, expected); + } } |