Index: pkg/analyzer_cli/lib/src/error_formatter.dart |
diff --git a/pkg/analyzer_cli/lib/src/error_formatter.dart b/pkg/analyzer_cli/lib/src/error_formatter.dart |
index 20a0efbd68140e664bacef1269335975bcf50427..722fbd2da540f2b0b4611dcb5d641a6fe9425ef4 100644 |
--- a/pkg/analyzer_cli/lib/src/error_formatter.dart |
+++ b/pkg/analyzer_cli/lib/src/error_formatter.dart |
@@ -108,6 +108,8 @@ class AnalysisStats { |
class ErrorFormatter { |
static final int _pipeCodeUnit = '|'.codeUnitAt(0); |
static final int _slashCodeUnit = '\\'.codeUnitAt(0); |
+ static final int _newline = '\n'.codeUnitAt(0); |
+ static final int _return = '\r'.codeUnitAt(0); |
final StringSink out; |
final CommandLineOptions options; |
@@ -144,7 +146,7 @@ class ErrorFormatter { |
out.write('|'); |
out.write(error.errorCode.name); |
out.write('|'); |
- out.write(escapePipe(source.fullName)); |
+ out.write(escapeForMachineMode(source.fullName)); |
out.write('|'); |
out.write(location.lineNumber); |
out.write('|'); |
@@ -152,7 +154,7 @@ class ErrorFormatter { |
out.write('|'); |
out.write(length); |
out.write('|'); |
- out.write(escapePipe(error.message)); |
+ out.write(escapeForMachineMode(error.message)); |
out.writeln(); |
} else { |
// Get display name. |
@@ -252,13 +254,19 @@ class ErrorFormatter { |
} |
} |
- static String escapePipe(String input) { |
+ static String escapeForMachineMode(String input) { |
StringBuffer result = new StringBuffer(); |
for (int c in input.codeUnits) { |
- if (c == _slashCodeUnit || c == _pipeCodeUnit) { |
- result.write('\\'); |
+ if (c == _newline) { |
+ result.write(r'\n'); |
+ } else if (c == _return) { |
+ result.write(r'\r'); |
+ } else { |
+ if (c == _slashCodeUnit || c == _pipeCodeUnit) { |
+ result.write('\\'); |
+ } |
+ result.writeCharCode(c); |
} |
- result.writeCharCode(c); |
} |
return result.toString(); |
} |