| 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 library matcher.pretty_print; | 5 library matcher.pretty_print; |
| 6 | 6 |
| 7 import 'description.dart'; | 7 import 'description.dart'; |
| 8 import 'interfaces.dart'; | 8 import 'interfaces.dart'; |
| 9 import 'util.dart'; |
| 9 | 10 |
| 10 /// Returns a pretty-printed representation of [object]. | 11 /// Returns a pretty-printed representation of [object]. |
| 11 /// | 12 /// |
| 12 /// If [maxLineLength] is passed, this will attempt to ensure that each line is | 13 /// If [maxLineLength] is passed, this will attempt to ensure that each line is |
| 13 /// no longer than [maxLineLength] characters long. This isn't guaranteed, since | 14 /// no longer than [maxLineLength] characters long. This isn't guaranteed, since |
| 14 /// individual objects may have string representations that are too long, but | 15 /// individual objects may have string representations that are too long, but |
| 15 /// most lines will be less than [maxLineLength] long. | 16 /// most lines will be less than [maxLineLength] long. |
| 16 /// | 17 /// |
| 17 /// If [maxItems] is passed, [Iterable]s and [Map]s will only print their first | 18 /// If [maxItems] is passed, [Iterable]s and [Map]s will only print their first |
| 18 /// [maxItems] members or key/value pairs, respectively. | 19 /// [maxItems] members or key/value pairs, respectively. |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 } catch (e) { | 126 } catch (e) { |
| 126 return "?"; | 127 return "?"; |
| 127 } | 128 } |
| 128 } | 129 } |
| 129 | 130 |
| 130 /// Returns [source] with any control characters replaced by their escape | 131 /// Returns [source] with any control characters replaced by their escape |
| 131 /// sequences. | 132 /// sequences. |
| 132 /// | 133 /// |
| 133 /// This doesn't add quotes to the string, but it does escape single quote | 134 /// This doesn't add quotes to the string, but it does escape single quote |
| 134 /// characters so that single quotes can be applied externally. | 135 /// characters so that single quotes can be applied externally. |
| 135 String _escapeString(String source) => | 136 String _escapeString(String source) => escape(source).replaceAll("'", r"\'"); |
| 136 source.split("").map(_escapeChar).join(""); | |
| 137 | |
| 138 /// Return the escaped form of a character [ch]. | |
| 139 String _escapeChar(String ch) { | |
| 140 switch (ch) { | |
| 141 case "'": | |
| 142 return "\\'"; | |
| 143 case '\n': | |
| 144 return '\\n'; | |
| 145 case '\r': | |
| 146 return '\\r'; | |
| 147 case '\t': | |
| 148 return '\\t'; | |
| 149 default: | |
| 150 return ch; | |
| 151 } | |
| 152 } | |
| OLD | NEW |