Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 } | |
| OLD | NEW |