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 import 'dart:convert' show UTF8; | 8 import 'dart:convert' show UTF8; |
9 | 9 |
10 /** | 10 /** |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 | 111 |
112 /** | 112 /** |
113 * Create a pretty string representation from a character position | 113 * Create a pretty string representation from a character position |
114 * in the file. | 114 * in the file. |
115 */ | 115 */ |
116 String getLocationMessage(String message, int start, int end, | 116 String getLocationMessage(String message, int start, int end, |
117 bool includeText, String color(String x)) { | 117 bool includeText, String color(String x)) { |
118 var line = getLine(start); | 118 var line = getLine(start); |
119 var column = getColumn(line, start); | 119 var column = getColumn(line, start); |
120 | 120 |
121 var buf = new StringBuffer( | 121 var buf = new StringBuffer('${filename}:'); |
122 '${filename}:${line + 1}:${column + 1}: $message'); | 122 if (start != end || start != 0) { |
123 if (includeText) { | 123 // Line/column info is relevant. |
124 buf.write('\n'); | 124 buf.write('${line + 1}:${column + 1}:'); |
125 } | |
126 buf.write('\n$message\n'); | |
ahe
2014/06/19 14:23:03
Why did you add a newline before the message?
It
Johnni Winther
2014/06/19 18:45:10
Because on the command line the hint (at the begin
ahe
2014/06/19 18:58:03
Makes sense. I'll add a comment.
How would feel a
Johnni Winther
2014/06/19 20:08:48
Sounds good.
| |
127 | |
128 if (start != end && includeText) { | |
125 String textLine; | 129 String textLine; |
126 // +1 for 0-indexing, +1 again to avoid the last line of the file | 130 // +1 for 0-indexing, +1 again to avoid the last line of the file |
127 if ((line + 2) < lineStarts.length) { | 131 if ((line + 2) < lineStarts.length) { |
128 textLine = slowSubstring(lineStarts[line], lineStarts[line+1]); | 132 textLine = slowSubstring(lineStarts[line], lineStarts[line+1]); |
129 } else { | 133 } else { |
130 textLine = '${slowSubstring(lineStarts[line], length)}\n'; | 134 textLine = '${slowSubstring(lineStarts[line], length)}\n'; |
131 } | 135 } |
132 | 136 |
133 int toColumn = min(column + (end-start), textLine.length); | 137 int toColumn = min(column + (end-start), textLine.length); |
134 buf.write(textLine.substring(0, column)); | 138 buf.write(textLine.substring(0, column)); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
185 | 189 |
186 int get length => text.length; | 190 int get length => text.length; |
187 set length(int v) { } | 191 set length(int v) { } |
188 | 192 |
189 String slowText() => text; | 193 String slowText() => text; |
190 | 194 |
191 List<int> slowUtf8Bytes() => UTF8.encode(text); | 195 List<int> slowUtf8Bytes() => UTF8.encode(text); |
192 | 196 |
193 String slowSubstring(int start, int end) => text.substring(start, end); | 197 String slowSubstring(int start, int end) => text.substring(start, end); |
194 } | 198 } |
OLD | NEW |