summaryrefslogtreecommitdiff
path: root/lib/Unescaper.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Unescaper.js')
-rw-r--r--lib/Unescaper.js146
1 files changed, 83 insertions, 63 deletions
diff --git a/lib/Unescaper.js b/lib/Unescaper.js
index c4a707a..d0c826e 100644
--- a/lib/Unescaper.js
+++ b/lib/Unescaper.js
@@ -1,4 +1,4 @@
-// Generated by CoffeeScript 1.12.4
+// Generated by CoffeeScript 2.4.1
var Pattern, Unescaper, Utils;
Utils = require('./Utils');
@@ -6,78 +6,98 @@ Utils = require('./Utils');
Pattern = require('./Pattern');
Unescaper = (function() {
- function Unescaper() {}
+ // Unescaper encapsulates unescaping rules for single and double-quoted YAML strings.
- Unescaper.PATTERN_ESCAPED_CHARACTER = new Pattern('\\\\([0abt\tnvfre "\\/\\\\N_LP]|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8})');
+ class Unescaper {
+ static unescapeSingleQuotedString(value) {
+ return value.replace(/\'\'/g, '\'');
+ }
- Unescaper.unescapeSingleQuotedString = function(value) {
- return value.replace(/\'\'/g, '\'');
- };
+ // Unescapes a double quoted string.
- Unescaper.unescapeDoubleQuotedString = function(value) {
- if (this._unescapeCallback == null) {
- this._unescapeCallback = (function(_this) {
- return function(str) {
- return _this.unescapeCharacter(str);
+ // @param [String] value A double quoted string.
+
+ // @return [String] The unescaped string.
+
+ static unescapeDoubleQuotedString(value) {
+ if (this._unescapeCallback == null) {
+ this._unescapeCallback = (str) => {
+ return this.unescapeCharacter(str);
};
- })(this);
+ }
+ // Evaluate the string
+ return this.PATTERN_ESCAPED_CHARACTER.replace(value, this._unescapeCallback);
}
- return this.PATTERN_ESCAPED_CHARACTER.replace(value, this._unescapeCallback);
- };
- Unescaper.unescapeCharacter = function(value) {
- var ch;
- ch = String.fromCharCode;
- switch (value.charAt(1)) {
- case '0':
- return ch(0);
- case 'a':
- return ch(7);
- case 'b':
- return ch(8);
- case 't':
- return "\t";
- case "\t":
- return "\t";
- case 'n':
- return "\n";
- case 'v':
- return ch(11);
- case 'f':
- return ch(12);
- case 'r':
- return ch(13);
- case 'e':
- return ch(27);
- case ' ':
- return ' ';
- case '"':
- return '"';
- case '/':
- return '/';
- case '\\':
- return '\\';
- case 'N':
- return ch(0x0085);
- case '_':
- return ch(0x00A0);
- case 'L':
- return ch(0x2028);
- case 'P':
- return ch(0x2029);
- case 'x':
- return Utils.utf8chr(Utils.hexDec(value.substr(2, 2)));
- case 'u':
- return Utils.utf8chr(Utils.hexDec(value.substr(2, 4)));
- case 'U':
- return Utils.utf8chr(Utils.hexDec(value.substr(2, 8)));
- default:
- return '';
+ // Unescapes a character that was found in a double-quoted string
+
+ // @param [String] value An escaped character
+
+ // @return [String] The unescaped character
+
+ static unescapeCharacter(value) {
+ var ch;
+ ch = String.fromCharCode;
+ switch (value.charAt(1)) {
+ case '0':
+ return ch(0);
+ case 'a':
+ return ch(7);
+ case 'b':
+ return ch(8);
+ case 't':
+ return "\t";
+ case "\t":
+ return "\t";
+ case 'n':
+ return "\n";
+ case 'v':
+ return ch(11);
+ case 'f':
+ return ch(12);
+ case 'r':
+ return ch(13);
+ case 'e':
+ return ch(27);
+ case ' ':
+ return ' ';
+ case '"':
+ return '"';
+ case '/':
+ return '/';
+ case '\\':
+ return '\\';
+ case 'N':
+ // U+0085 NEXT LINE
+ return ch(0x0085);
+ case '_':
+ // U+00A0 NO-BREAK SPACE
+ return ch(0x00A0);
+ case 'L':
+ // U+2028 LINE SEPARATOR
+ return ch(0x2028);
+ case 'P':
+ // U+2029 PARAGRAPH SEPARATOR
+ return ch(0x2029);
+ case 'x':
+ return Utils.utf8chr(Utils.hexDec(value.substr(2, 2)));
+ case 'u':
+ return Utils.utf8chr(Utils.hexDec(value.substr(2, 4)));
+ case 'U':
+ return Utils.utf8chr(Utils.hexDec(value.substr(2, 8)));
+ default:
+ return '';
+ }
}
+
};
+ // Regex fragment that matches an escaped character in
+ // a double quoted string.
+ Unescaper.PATTERN_ESCAPED_CHARACTER = new Pattern('\\\\([0abt\tnvfre "\\/\\\\N_LP]|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8})');
+
return Unescaper;
-})();
+}).call(this);
module.exports = Unescaper;