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

Unified Diff: lib/src/util.dart

Issue 984463002: Improve the formatting of strings that contain unprintable ASCII characters. (Closed) Base URL: git@github.com:dart-lang/matcher@master
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/util.dart
diff --git a/lib/src/util.dart b/lib/src/util.dart
index a99d2dd1f9fcbedc02722b5349216a2dbc1f260c..659faeade879e09e7b04f96a94e28729d52b39f8 100644
--- a/lib/src/util.dart
+++ b/lib/src/util.dart
@@ -15,11 +15,13 @@ const _escapeMap = const {
'\b': r'\b',
'\t': r'\t',
'\v': r'\v',
+ '\v': r'\v',
kevmoo 2015/03/04 23:07:29 double entry?
nweiz 2015/03/05 00:50:11 Done.
+ '\x7F': r'\x7F',
kevmoo 2015/03/04 23:07:29 Add a comment for which character this is?
nweiz 2015/03/05 00:50:11 Done.
};
/// A [RegExp] that matches whitespace characters that should be escaped.
-final _escapeRegExp =
- new RegExp("[${_escapeMap.keys.map(_getHexLiteral).join()}]");
+final _escapeRegExp = new RegExp(
+ "[\\x00-\\x07\\x0E-\\x1F${_escapeMap.keys.map(_getHexLiteral).join()}]");
/// Useful utility for nesting match states.
void addStateInfo(Map matchState, Map values) {
@@ -51,12 +53,14 @@ Matcher wrapMatcher(x) {
String escape(String str) {
str = str.replaceAll('\\', r'\\');
return str.replaceAllMapped(_escapeRegExp, (match) {
- return _escapeMap[match[0]];
+ var mapped = _escapeMap[match[0]];
+ if (mapped != null) return mapped;
+ return _getHexLiteral(match[0]);
});
}
/// Given single-character string, return the hex-escaped equivalent.
String _getHexLiteral(String input) {
int rune = input.runes.single;
- return r'\x' + rune.toRadixString(16).padLeft(2, '0');
+ return r'\x' + rune.toRadixString(16).toUpperCase().padLeft(2, '0');
}
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698