| 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 /// Contains a code printer that generates code by recording the source maps. | 5 /// Contains a code printer that generates code by recording the source maps. |
| 6 library source_maps.printer; | 6 library source_maps.printer; |
| 7 | 7 |
| 8 import 'dart:utf' show stringToCodepoints; | |
| 9 import 'builder.dart'; | 8 import 'builder.dart'; |
| 10 import 'span.dart'; | 9 import 'span.dart'; |
| 11 | 10 |
| 12 const int _LF = 10; | 11 const int _LF = 10; |
| 13 const int _CR = 13; | 12 const int _CR = 13; |
| 14 | 13 |
| 15 /// A simple printer that keeps track of offset locations and records source | 14 /// A simple printer that keeps track of offset locations and records source |
| 16 /// maps locations. | 15 /// maps locations. |
| 17 class Printer { | 16 class Printer { |
| 18 final String filename; | 17 final String filename; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 31 int _column = 0; | 30 int _column = 0; |
| 32 | 31 |
| 33 Printer(this.filename); | 32 Printer(this.filename); |
| 34 | 33 |
| 35 /// Add [str] contents to the output, tracking new lines to track correct | 34 /// Add [str] contents to the output, tracking new lines to track correct |
| 36 /// positions for span locations. When [projectMarks] is true, this method | 35 /// positions for span locations. When [projectMarks] is true, this method |
| 37 /// adds a source map location on each new line, projecting that every new | 36 /// adds a source map location on each new line, projecting that every new |
| 38 /// line in the target file (printed here) corresponds to a new line in the | 37 /// line in the target file (printed here) corresponds to a new line in the |
| 39 /// source file. | 38 /// source file. |
| 40 void add(String str, {projectMarks: false}) { | 39 void add(String str, {projectMarks: false}) { |
| 41 var chars = stringToCodepoints(str); | 40 var chars = str.runes.toList(); |
| 42 var length = chars.length; | 41 var length = chars.length; |
| 43 for (int i = 0; i < length; i++) { | 42 for (int i = 0; i < length; i++) { |
| 44 var c = chars[i]; | 43 var c = chars[i]; |
| 45 if (c == _LF || (c == _CR && (i + 1 == length || chars[i + 1] != _LF))) { | 44 if (c == _LF || (c == _CR && (i + 1 == length || chars[i + 1] != _LF))) { |
| 46 // Return not followed by line-feed is treated as a new line. | 45 // Return not followed by line-feed is treated as a new line. |
| 47 _line++; | 46 _line++; |
| 48 _column = 0; | 47 _column = 0; |
| 49 if (projectMarks && _loc != null) { | 48 if (projectMarks && _loc != null) { |
| 50 if (_loc is FixedLocation) { | 49 if (_loc is FixedLocation) { |
| 51 mark(new FixedLocation(0, _loc.sourceUrl, _loc.line + 1, 0)); | 50 mark(new FixedLocation(0, _loc.sourceUrl, _loc.line + 1, 0)); |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 } | 235 } |
| 237 } | 236 } |
| 238 } | 237 } |
| 239 } | 238 } |
| 240 | 239 |
| 241 /// An item added to a [NestedPrinter]. | 240 /// An item added to a [NestedPrinter]. |
| 242 abstract class NestedItem { | 241 abstract class NestedItem { |
| 243 /// Write the contents of this item into [printer]. | 242 /// Write the contents of this item into [printer]. |
| 244 void writeTo(Printer printer); | 243 void writeTo(Printer printer); |
| 245 } | 244 } |
| OLD | NEW |