OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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_span.file; | |
6 | |
7 import 'dart:math' as math; | 5 import 'dart:math' as math; |
8 import 'dart:typed_data'; | 6 import 'dart:typed_data'; |
9 | 7 |
10 import 'location.dart'; | 8 import 'location.dart'; |
11 import 'location_mixin.dart'; | 9 import 'location_mixin.dart'; |
12 import 'span.dart'; | 10 import 'span.dart'; |
13 import 'span_mixin.dart'; | 11 import 'span_mixin.dart'; |
14 import 'span_with_context.dart'; | 12 import 'span_with_context.dart'; |
15 | 13 |
16 // Constants to determine end-of-lines. | 14 // Constants to determine end-of-lines. |
(...skipping 27 matching lines...) Expand all Loading... |
44 int get lines => _lineStarts.length; | 42 int get lines => _lineStarts.length; |
45 | 43 |
46 /// The line that the offset fell on the last time [getLine] was called. | 44 /// The line that the offset fell on the last time [getLine] was called. |
47 /// | 45 /// |
48 /// In many cases, sequential calls to getLine() are for nearby, usually | 46 /// In many cases, sequential calls to getLine() are for nearby, usually |
49 /// increasing offsets. In that case, we can find the line for an offset | 47 /// increasing offsets. In that case, we can find the line for an offset |
50 /// quickly by first checking to see if the offset is on the same line as the | 48 /// quickly by first checking to see if the offset is on the same line as the |
51 /// previous result. | 49 /// previous result. |
52 int _cachedLine; | 50 int _cachedLine; |
53 | 51 |
| 52 /// This constructor is deprecated. |
| 53 /// |
| 54 /// Use [new SourceFile.fromString] instead. |
| 55 @Deprecated("Will be removed in 2.0.0") |
| 56 SourceFile(String text, {url}) |
| 57 : this.decoded(text.runes, url: url); |
| 58 |
54 /// Creates a new source file from [text]. | 59 /// Creates a new source file from [text]. |
55 /// | 60 /// |
56 /// [url] may be either a [String], a [Uri], or `null`. | 61 /// [url] may be either a [String], a [Uri], or `null`. |
57 SourceFile(String text, {url}) | 62 SourceFile.fromString(String text, {url}) |
58 : this.decoded(text.runes, url: url); | 63 : this.decoded(text.codeUnits, url: url); |
59 | 64 |
60 /// Creates a new source file from a list of decoded characters. | 65 /// Creates a new source file from a list of decoded code units. |
61 /// | 66 /// |
62 /// [url] may be either a [String], a [Uri], or `null`. | 67 /// [url] may be either a [String], a [Uri], or `null`. |
| 68 /// |
| 69 /// Currently, if [decodedChars] contains characters larger than `0xFFFF`, |
| 70 /// they'll be treated as single characters rather than being split into |
| 71 /// surrogate pairs. **This behavior is deprecated**. For |
| 72 /// forwards-compatibility, callers should only pass in characters less than |
| 73 /// or equal to `0xFFFF`. |
63 SourceFile.decoded(Iterable<int> decodedChars, {url}) | 74 SourceFile.decoded(Iterable<int> decodedChars, {url}) |
64 : url = url is String ? Uri.parse(url) : url, | 75 : url = url is String ? Uri.parse(url) : url, |
65 _decodedChars = new Uint32List.fromList(decodedChars.toList()) { | 76 _decodedChars = new Uint32List.fromList(decodedChars.toList()) { |
66 for (var i = 0; i < _decodedChars.length; i++) { | 77 for (var i = 0; i < _decodedChars.length; i++) { |
67 var c = _decodedChars[i]; | 78 var c = _decodedChars[i]; |
68 if (c == _CR) { | 79 if (c == _CR) { |
69 // Return not followed by newline is treated as a newline | 80 // Return not followed by newline is treated as a newline |
70 var j = i + 1; | 81 var j = i + 1; |
71 if (j >= _decodedChars.length || _decodedChars[j] != _LF) c = _LF; | 82 if (j >= _decodedChars.length || _decodedChars[j] != _LF) c = _LF; |
72 } | 83 } |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 var start = math.min(this._start, other._start); | 360 var start = math.min(this._start, other._start); |
350 var end = math.max(this._end, other._end); | 361 var end = math.max(this._end, other._end); |
351 return new _FileSpan(file, start, end); | 362 return new _FileSpan(file, start, end); |
352 } else { | 363 } else { |
353 var start = math.min(this._start, other.start.offset); | 364 var start = math.min(this._start, other.start.offset); |
354 var end = math.max(this._end, other.end.offset); | 365 var end = math.max(this._end, other.end.offset); |
355 return new _FileSpan(file, start, end); | 366 return new _FileSpan(file, start, end); |
356 } | 367 } |
357 } | 368 } |
358 } | 369 } |
OLD | NEW |