Initial commit
[yaffs-website] / node_modules / grunt-contrib-watch / node_modules / lodash / internal / escapeRegExpChar.js
1 /** Used to escape characters for inclusion in compiled regexes. */
2 var regexpEscapes = {
3   '0': 'x30', '1': 'x31', '2': 'x32', '3': 'x33', '4': 'x34',
4   '5': 'x35', '6': 'x36', '7': 'x37', '8': 'x38', '9': 'x39',
5   'A': 'x41', 'B': 'x42', 'C': 'x43', 'D': 'x44', 'E': 'x45', 'F': 'x46',
6   'a': 'x61', 'b': 'x62', 'c': 'x63', 'd': 'x64', 'e': 'x65', 'f': 'x66',
7   'n': 'x6e', 'r': 'x72', 't': 'x74', 'u': 'x75', 'v': 'x76', 'x': 'x78'
8 };
9
10 /** Used to escape characters for inclusion in compiled string literals. */
11 var stringEscapes = {
12   '\\': '\\',
13   "'": "'",
14   '\n': 'n',
15   '\r': 'r',
16   '\u2028': 'u2028',
17   '\u2029': 'u2029'
18 };
19
20 /**
21  * Used by `_.escapeRegExp` to escape characters for inclusion in compiled regexes.
22  *
23  * @private
24  * @param {string} chr The matched character to escape.
25  * @param {string} leadingChar The capture group for a leading character.
26  * @param {string} whitespaceChar The capture group for a whitespace character.
27  * @returns {string} Returns the escaped character.
28  */
29 function escapeRegExpChar(chr, leadingChar, whitespaceChar) {
30   if (leadingChar) {
31     chr = regexpEscapes[chr];
32   } else if (whitespaceChar) {
33     chr = stringEscapes[chr];
34   }
35   return '\\' + chr;
36 }
37
38 module.exports = escapeRegExpChar;