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

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

Issue 891463004: Correctly match and print strings with escaped values (Closed) Base URL: https://github.com/dart-lang/matcher.git@master
Patch Set: cleanup 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
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
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.
4
5 library matcher.escape;
6
7 const _escapMap = const {
nweiz 2015/02/04 01:34:45 "escapMap" -> "escapeMap"
kevmoo 2015/02/04 05:28:21 Done.
8 '\n': r'\n',
9 '\r': r'\r',
10 '\f': r'\f',
11 '\b': r'\b',
12 '\t': r'\t',
13 '\v': r'\v',
14 };
15
16 final _escapeStr = "[" + _escapMap.keys.map(_getHexLiteral).join() + "]";
nweiz 2015/02/04 01:34:45 Just inline this in the regexp definition.
kevmoo 2015/02/04 05:28:21 Done.
17
18 final _escapeRegExp = new RegExp(_escapeStr);
19
20 String escape(String s) {
nweiz 2015/02/04 01:34:45 Put this in utils. Also, document everything in he
kevmoo 2015/02/04 05:28:21 Done.
kevmoo 2015/02/04 05:28:21 Done.
21 s = s.replaceAll('\\', r'\\');
22 return s.replaceAllMapped(_escapeRegExp, (m) {
23 return _escapMap[m.input];
24 });
25 }
26
27 String _getHexLiteral(String input) {
28 int rune = input.runes.single;
29 return r'\x' + rune.toRadixString(16).padLeft(2, '0');
30 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698