gorillajs
Version:
A smart development environment designed to easily install and neatly manage web applications. Gorilla JS frees you from the repetitive daily tasks like apps installation, database management, creation of virtual environment, server configuration… And it
57 lines (40 loc) • 2.2 kB
JavaScript
// Generated by CoffeeScript 1.12.4
var Escaper, Pattern;
Pattern = require('./Pattern');
Escaper = (function() {
var ch;
function Escaper() {}
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)];
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"];
Escaper.MAPPING_ESCAPEES_TO_ESCAPED = (function() {
var i, j, mapping, ref;
mapping = {};
for (i = j = 0, ref = Escaper.LIST_ESCAPEES.length; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) {
mapping[Escaper.LIST_ESCAPEES[i]] = Escaper.LIST_ESCAPED[i];
}
return mapping;
})();
Escaper.PATTERN_CHARACTERS_TO_ESCAPE = new Pattern('[\\x00-\\x1f]|\xc2\x85|\xc2\xa0|\xe2\x80\xa8|\xe2\x80\xa9');
Escaper.PATTERN_MAPPING_ESCAPEES = new Pattern(Escaper.LIST_ESCAPEES.join('|').split('\\').join('\\\\'));
Escaper.PATTERN_SINGLE_QUOTING = new Pattern('[\\s\'":{}[\\],&*#?]|^[-?|<>=!%@`]');
Escaper.requiresDoubleQuoting = function(value) {
return this.PATTERN_CHARACTERS_TO_ESCAPE.test(value);
};
Escaper.escapeWithDoubleQuotes = function(value) {
var result;
result = this.PATTERN_MAPPING_ESCAPEES.replace(value, (function(_this) {
return function(str) {
return _this.MAPPING_ESCAPEES_TO_ESCAPED[str];
};
})(this));
return '"' + result + '"';
};
Escaper.requiresSingleQuoting = function(value) {
return this.PATTERN_SINGLE_QUOTING.test(value);
};
Escaper.escapeWithSingleQuotes = function(value) {
return "'" + value.replace(/'/g, "''") + "'";
};
return Escaper;
})();
module.exports = Escaper;