scratch – Blame information for rev 125
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
125 | office | 1 | // Generated by CoffeeScript 1.12.4 |
75 | office | 2 | var Escaper, Pattern; |
3 | |||
4 | Pattern = require('./Pattern'); |
||
5 | |||
6 | Escaper = (function() { |
||
7 | var ch; |
||
8 | |||
9 | function Escaper() {} |
||
10 | |||
11 | Escaper.LIST_ESCAPEES = ['\\', '\\\\', '\\"', '"', "\x00", "\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", "\x08", "\x09", "\x0a", "\x0b", "\x0c", "\x0d", "\x0e", "\x0f", "\x10", "\x11", "\x12", "\x13", "\x14", "\x15", "\x16", "\x17", "\x18", "\x19", "\x1a", "\x1b", "\x1c", "\x1d", "\x1e", "\x1f", (ch = String.fromCharCode)(0x0085), ch(0x00A0), ch(0x2028), ch(0x2029)]; |
||
12 | |||
13 | Escaper.LIST_ESCAPED = ['\\\\', '\\"', '\\"', '\\"', "\\0", "\\x01", "\\x02", "\\x03", "\\x04", "\\x05", "\\x06", "\\a", "\\b", "\\t", "\\n", "\\v", "\\f", "\\r", "\\x0e", "\\x0f", "\\x10", "\\x11", "\\x12", "\\x13", "\\x14", "\\x15", "\\x16", "\\x17", "\\x18", "\\x19", "\\x1a", "\\e", "\\x1c", "\\x1d", "\\x1e", "\\x1f", "\\N", "\\_", "\\L", "\\P"]; |
||
14 | |||
15 | Escaper.MAPPING_ESCAPEES_TO_ESCAPED = (function() { |
||
16 | var i, j, mapping, ref; |
||
17 | mapping = {}; |
||
18 | for (i = j = 0, ref = Escaper.LIST_ESCAPEES.length; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) { |
||
19 | mapping[Escaper.LIST_ESCAPEES[i]] = Escaper.LIST_ESCAPED[i]; |
||
20 | } |
||
21 | return mapping; |
||
22 | })(); |
||
23 | |||
24 | Escaper.PATTERN_CHARACTERS_TO_ESCAPE = new Pattern('[\\x00-\\x1f]|\xc2\x85|\xc2\xa0|\xe2\x80\xa8|\xe2\x80\xa9'); |
||
25 | |||
26 | Escaper.PATTERN_MAPPING_ESCAPEES = new Pattern(Escaper.LIST_ESCAPEES.join('|').split('\\').join('\\\\')); |
||
27 | |||
28 | Escaper.PATTERN_SINGLE_QUOTING = new Pattern('[\\s\'":{}[\\],&*#?]|^[-?|<>=!%@`]'); |
||
29 | |||
30 | Escaper.requiresDoubleQuoting = function(value) { |
||
31 | return this.PATTERN_CHARACTERS_TO_ESCAPE.test(value); |
||
32 | }; |
||
33 | |||
34 | Escaper.escapeWithDoubleQuotes = function(value) { |
||
35 | var result; |
||
36 | result = this.PATTERN_MAPPING_ESCAPEES.replace(value, (function(_this) { |
||
37 | return function(str) { |
||
38 | return _this.MAPPING_ESCAPEES_TO_ESCAPED[str]; |
||
39 | }; |
||
40 | })(this)); |
||
41 | return '"' + result + '"'; |
||
42 | }; |
||
43 | |||
44 | Escaper.requiresSingleQuoting = function(value) { |
||
45 | return this.PATTERN_SINGLE_QUOTING.test(value); |
||
46 | }; |
||
47 | |||
48 | Escaper.escapeWithSingleQuotes = function(value) { |
||
49 | return "'" + value.replace(/'/g, "''") + "'"; |
||
50 | }; |
||
51 | |||
52 | return Escaper; |
||
53 | |||
54 | })(); |
||
55 | |||
56 | module.exports = Escaper; |