Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: lib/src/pretty_print.dart

Issue 891463004: Correctly match and print strings with escaped values (Closed) Base URL: https://github.com/dart-lang/matcher.git@master
Patch Set: nits Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/src/core_matchers.dart ('k') | lib/src/util.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 }
OLDNEW
« no previous file with comments | « lib/src/core_matchers.dart ('k') | lib/src/util.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698