OLD | NEW |
1 library inputstream; | 1 library inputstream; |
2 | 2 |
3 import 'dart:collection'; | 3 import 'dart:collection'; |
4 import 'package:utf/utf.dart'; | 4 import 'package:utf/utf.dart'; |
5 import 'package:source_maps/span.dart' show SourceFile; | 5 import 'package:source_span/source_span.dart'; |
6 import 'char_encodings.dart'; | 6 import 'char_encodings.dart'; |
7 import 'constants.dart'; | 7 import 'constants.dart'; |
8 import 'utils.dart'; | 8 import 'utils.dart'; |
9 import 'encoding_parser.dart'; | 9 import 'encoding_parser.dart'; |
10 | 10 |
11 /// Hooks to call into dart:io without directly referencing it. | 11 /// Hooks to call into dart:io without directly referencing it. |
12 class ConsoleSupport { | 12 class ConsoleSupport { |
13 List<int> bytesFromFile(source) => null; | 13 List<int> bytesFromFile(source) => null; |
14 } | 14 } |
15 | 15 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 c = NEWLINE; | 128 c = NEWLINE; |
129 } | 129 } |
130 | 130 |
131 _chars.add(c); | 131 _chars.add(c); |
132 if (c == NEWLINE) _lineStarts.add(_chars.length); | 132 if (c == NEWLINE) _lineStarts.add(_chars.length); |
133 } | 133 } |
134 | 134 |
135 // Free decoded characters if they aren't needed anymore. | 135 // Free decoded characters if they aren't needed anymore. |
136 if (_rawBytes != null) _rawChars = null; | 136 if (_rawBytes != null) _rawChars = null; |
137 | 137 |
138 fileInfo = new SourceFile(sourceUrl, _lineStarts, | 138 // TODO(sigmund): Don't parse the file at all if spans aren't being |
139 generateSpans ? _chars : null); | 139 // generated. |
| 140 fileInfo = new SourceFile.decoded(_chars, url: sourceUrl); |
140 } | 141 } |
141 | 142 |
142 | 143 |
143 void detectEncoding([bool parseMeta = true]) { | 144 void detectEncoding([bool parseMeta = true]) { |
144 // First look for a BOM | 145 // First look for a BOM |
145 // This will also read past the BOM if present | 146 // This will also read past the BOM if present |
146 charEncodingName = detectBOM(); | 147 charEncodingName = detectBOM(); |
147 charEncodingCertain = true; | 148 charEncodingCertain = true; |
148 | 149 |
149 // If there is no BOM need to look for meta elements with encoding | 150 // If there is no BOM need to look for meta elements with encoding |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 /// Return the python codec name corresponding to an encoding or null if the | 286 /// Return the python codec name corresponding to an encoding or null if the |
286 /// string doesn't correspond to a valid encoding. | 287 /// string doesn't correspond to a valid encoding. |
287 String codecName(String encoding) { | 288 String codecName(String encoding) { |
288 final asciiPunctuation = new RegExp( | 289 final asciiPunctuation = new RegExp( |
289 "[\u0009-\u000D\u0020-\u002F\u003A-\u0040\u005B-\u0060\u007B-\u007E]"); | 290 "[\u0009-\u000D\u0020-\u002F\u003A-\u0040\u005B-\u0060\u007B-\u007E]"); |
290 | 291 |
291 if (encoding == null) return null; | 292 if (encoding == null) return null; |
292 var canonicalName = encoding.replaceAll(asciiPunctuation, '').toLowerCase(); | 293 var canonicalName = encoding.replaceAll(asciiPunctuation, '').toLowerCase(); |
293 return encodings[canonicalName]; | 294 return encodings[canonicalName]; |
294 } | 295 } |
OLD | NEW |