@@ -75,6 +75,7 @@ static String wrap(final int columnLimit, final String input) throws FormatterEx
7575 }
7676
7777 JCTree .JCCompilationUnit unit = parse (input , /* allowStringFolding= */ false );
78+ String separator = Newlines .guessLineSeparator (input );
7879
7980 // Paths to string literals that extend past the column limit.
8081 List <TreePath > toFix = new ArrayList <>();
@@ -133,7 +134,7 @@ public Void visitLiteral(LiteralTree literalTree, Void aVoid) {
133134 ImmutableList <String > components = stringComponents (input , unit , flat );
134135 replacements .put (
135136 Range .closedOpen (getStartPosition (flat .get (0 )), getEndPosition (unit , getLast (flat ))),
136- reflow (columnLimit , startColumn , trailing , components , first .get ()));
137+ reflow (separator , columnLimit , startColumn , trailing , components , first .get ()));
137138 }
138139 String result = applyReplacements (input , replacements );
139140
@@ -207,7 +208,7 @@ static int hasEscapedWhitespaceAt(String input, int idx) {
207208 }
208209
209210 static int hasEscapedNewlineAt (String input , int idx ) {
210- return Stream .of ("\\ n \\ r " , "\\ r" , "\\ n" )
211+ return Stream .of ("\\ r \\ n " , "\\ r" , "\\ n" )
211212 .mapToInt (x -> input .startsWith (x , idx ) ? x .length () : -1 )
212213 .filter (x -> x != -1 )
213214 .findFirst ()
@@ -217,13 +218,15 @@ static int hasEscapedNewlineAt(String input, int idx) {
217218 /**
218219 * Reflows the given source text, trying to split on word boundaries.
219220 *
221+ * @param separator the line separator
220222 * @param columnLimit the number of columns to wrap at
221223 * @param startColumn the column position of the beginning of the original text
222224 * @param trailing extra space to leave after the last line
223225 * @param components the text to reflow
224226 * @param first0 true if the text includes the beginning of its enclosing concat chain, i.e. a
225227 */
226228 private static String reflow (
229+ String separator ,
227230 int columnLimit ,
228231 int startColumn ,
229232 int trailing ,
@@ -263,7 +266,7 @@ private static String reflow(
263266 return lines .stream ()
264267 .collect (
265268 joining (
266- "\" \n " + Strings .repeat (" " , startColumn + (first0 ? 4 : -2 )) + "+ \" " ,
269+ "\" " + separator + Strings .repeat (" " , startColumn + (first0 ? 4 : -2 )) + "+ \" " ,
267270 "\" " ,
268271 "\" " ));
269272 }
0 commit comments