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'); |
} |