| 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; | |
| 9 import 'dart:math' show min, max; | 8 import 'dart:math' show min, max; |
| 10 | 9 |
| 11 import 'src/utils.dart'; | 10 import 'src/utils.dart'; |
| 12 | 11 |
| 13 /// A simple class that describe a segment of source text. | 12 /// A simple class that describe a segment of source text. |
| 14 abstract class Span implements Comparable { | 13 abstract class Span implements Comparable { |
| 15 /// The start location of this span. | 14 /// The start location of this span. |
| 16 final Location start; | 15 final Location start; |
| 17 | 16 |
| 18 /// The end location of this span, exclusive. | 17 /// The end location of this span, exclusive. |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 class SourceFile { | 193 class SourceFile { |
| 195 /// Url where the source file is located. | 194 /// Url where the source file is located. |
| 196 final String url; | 195 final String url; |
| 197 final List<int> _lineStarts; | 196 final List<int> _lineStarts; |
| 198 final List<int> _decodedChars; | 197 final List<int> _decodedChars; |
| 199 | 198 |
| 200 SourceFile(this.url, this._lineStarts, this._decodedChars); | 199 SourceFile(this.url, this._lineStarts, this._decodedChars); |
| 201 | 200 |
| 202 SourceFile.text(this.url, String text) | 201 SourceFile.text(this.url, String text) |
| 203 : _lineStarts = <int>[0], | 202 : _lineStarts = <int>[0], |
| 204 _decodedChars = stringToCodepoints(text) { | 203 _decodedChars = text.runes.toList() { |
| 205 for (int i = 0; i < _decodedChars.length; i++) { | 204 for (int i = 0; i < _decodedChars.length; i++) { |
| 206 var c = _decodedChars[i]; | 205 var c = _decodedChars[i]; |
| 207 if (c == _CR) { | 206 if (c == _CR) { |
| 208 // Return not followed by newline is treated as a newline | 207 // Return not followed by newline is treated as a newline |
| 209 int j = i + 1; | 208 int j = i + 1; |
| 210 if (j >= _decodedChars.length || _decodedChars[j] != _LF) { | 209 if (j >= _decodedChars.length || _decodedChars[j] != _LF) { |
| 211 c = _LF; | 210 c = _LF; |
| 212 } | 211 } |
| 213 } | 212 } |
| 214 if (c == _LF) _lineStarts.add(i + 1); | 213 if (c == _LF) _lineStarts.add(i + 1); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 int getOffset(int line, int column) => | 351 int getOffset(int line, int column) => |
| 353 super.getOffset(line - _baseLine, | 352 super.getOffset(line - _baseLine, |
| 354 line == _baseLine ? column - _baseColumn : column) + _baseOffset; | 353 line == _baseLine ? column - _baseColumn : column) + _baseOffset; |
| 355 | 354 |
| 356 /// Retrieve the text associated with the specified range. This method | 355 /// Retrieve the text associated with the specified range. This method |
| 357 /// operates on the real offsets from the original file, so that error | 356 /// operates on the real offsets from the original file, so that error |
| 358 /// messages can be reported accurately. | 357 /// messages can be reported accurately. |
| 359 String getText(int start, [int end]) => | 358 String getText(int start, [int end]) => |
| 360 super.getText(start - _baseOffset, end == null ? null : end - _baseOffset); | 359 super.getText(start - _baseOffset, end == null ? null : end - _baseOffset); |
| 361 } | 360 } |
| OLD | NEW |