| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library source_file; | 5 library source_file; |
| 6 | 6 |
| 7 import 'dart:math'; | 7 import 'dart:math'; |
| 8 | 8 |
| 9 import 'colors.dart' as colors; | 9 import 'colors.dart' as colors; |
| 10 | 10 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 * in the file. | 69 * in the file. |
| 70 */ | 70 */ |
| 71 String getLocationMessage(String message, int start, int end, | 71 String getLocationMessage(String message, int start, int end, |
| 72 bool includeText, String color(String x)) { | 72 bool includeText, String color(String x)) { |
| 73 var line = getLine(start); | 73 var line = getLine(start); |
| 74 var column = getColumn(line, start); | 74 var column = getColumn(line, start); |
| 75 | 75 |
| 76 var buf = new StringBuffer( | 76 var buf = new StringBuffer( |
| 77 '${filename}:${line + 1}:${column + 1}: $message'); | 77 '${filename}:${line + 1}:${column + 1}: $message'); |
| 78 if (includeText) { | 78 if (includeText) { |
| 79 buf.add('\n'); | 79 buf.write('\n'); |
| 80 var textLine; | 80 var textLine; |
| 81 // +1 for 0-indexing, +1 again to avoid the last line of the file | 81 // +1 for 0-indexing, +1 again to avoid the last line of the file |
| 82 if ((line + 2) < _lineStarts.length) { | 82 if ((line + 2) < _lineStarts.length) { |
| 83 textLine = text.substring(_lineStarts[line], _lineStarts[line+1]); | 83 textLine = text.substring(_lineStarts[line], _lineStarts[line+1]); |
| 84 } else { | 84 } else { |
| 85 textLine = '${text.substring(_lineStarts[line])}\n'; | 85 textLine = '${text.substring(_lineStarts[line])}\n'; |
| 86 } | 86 } |
| 87 | 87 |
| 88 int toColumn = min(column + (end-start), textLine.length); | 88 int toColumn = min(column + (end-start), textLine.length); |
| 89 buf.add(textLine.substring(0, column)); | 89 buf.write(textLine.substring(0, column)); |
| 90 buf.add(color(textLine.substring(column, toColumn))); | 90 buf.write(color(textLine.substring(column, toColumn))); |
| 91 buf.add(textLine.substring(toColumn)); | 91 buf.write(textLine.substring(toColumn)); |
| 92 | 92 |
| 93 int i = 0; | 93 int i = 0; |
| 94 for (; i < column; i++) { | 94 for (; i < column; i++) { |
| 95 buf.add(' '); | 95 buf.write(' '); |
| 96 } | 96 } |
| 97 | 97 |
| 98 for (; i < toColumn; i++) { | 98 for (; i < toColumn; i++) { |
| 99 buf.add(color('^')); | 99 buf.write(color('^')); |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 | 102 |
| 103 return buf.toString(); | 103 return buf.toString(); |
| 104 } | 104 } |
| 105 } | 105 } |
| OLD | NEW |