OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /// Dart classes representing the souce spans and source files. | 5 /// Dart classes representing the souce spans and source files. |
6 library source_maps.span; | 6 library source_maps.span; |
7 | 7 |
8 import 'dart:utf' show stringToCodepoints, codepointsToString; | 8 import 'dart:utf' show stringToCodepoints; |
9 import 'dart:math' show min; | 9 import 'dart:math' show min; |
10 | 10 |
11 import 'src/utils.dart'; | 11 import 'src/utils.dart'; |
12 | 12 |
13 /// A simple class that describe a segment of source text. | 13 /// A simple class that describe a segment of source text. |
14 abstract class Span implements Comparable { | 14 abstract class Span implements Comparable { |
15 /// The start location of this span. | 15 /// The start location of this span. |
16 final Location start; | 16 final Location start; |
17 | 17 |
18 /// The end location of this span, exclusive. | 18 /// The end location of this span, exclusive. |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 return offset - _lineStarts[line]; | 225 return offset - _lineStarts[line]; |
226 } | 226 } |
227 | 227 |
228 /// Get the offset for a given line and column | 228 /// Get the offset for a given line and column |
229 int getOffset(int line, int column) { | 229 int getOffset(int line, int column) { |
230 return _lineStarts[min(line, _lineStarts.length - 1)] + column; | 230 return _lineStarts[min(line, _lineStarts.length - 1)] + column; |
231 } | 231 } |
232 | 232 |
233 /// Gets the text at the given offsets. | 233 /// Gets the text at the given offsets. |
234 String getText(int start, [int end]) { | 234 String getText(int start, [int end]) { |
235 return codepointsToString(_decodedChars.sublist(start, end)); | 235 return new String.fromCharCodes(_decodedChars.sublist(start, end)); |
236 } | 236 } |
237 | 237 |
238 /// Create a pretty string representation from a span. | 238 /// Create a pretty string representation from a span. |
239 String getLocationMessage(String message, int start, int end, | 239 String getLocationMessage(String message, int start, int end, |
240 {bool useColors: false, String color}) { | 240 {bool useColors: false, String color}) { |
241 // TODO(jmesserly): it would be more useful to pass in an object that | 241 // TODO(jmesserly): it would be more useful to pass in an object that |
242 // controls how the errors are printed. This method is a bit too smart. | 242 // controls how the errors are printed. This method is a bit too smart. |
243 var line = getLine(start); | 243 var line = getLine(start); |
244 var column = getColumn(line, start); | 244 var column = getColumn(line, start); |
245 | 245 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 return line == _baseLine ? col + _baseColumn : col; | 321 return line == _baseLine ? col + _baseColumn : col; |
322 } | 322 } |
323 | 323 |
324 int getOffset(int line, int column) => | 324 int getOffset(int line, int column) => |
325 super.getOffset(line - _baseLine, | 325 super.getOffset(line - _baseLine, |
326 line == _baseLine ? column - _baseColumn : column) + _baseOffset; | 326 line == _baseLine ? column - _baseColumn : column) + _baseOffset; |
327 | 327 |
328 String getText(int start, [int end]) => | 328 String getText(int start, [int end]) => |
329 super.getText(start - _baseOffset, end - _baseOffset); | 329 super.getText(start - _baseOffset, end - _baseOffset); |
330 } | 330 } |
OLD | NEW |