-// utf8 to unicode converter (used below in deoctalize()).
-// "fatal: true" means that the converter will throw an
-// exception if the input is not valid utf8.
-exports.decoder = new TextDecoder('utf8', {fatal: true});
-
-/* De-octalize an escaped string, and decode it from utf8.
- * If the input string contains anything unexpected (control
- * characters, invalid values after the backslash, character
- * sequences that are not valid utf8), return the input string.
- * */
-exports.deoctalize = function(str) {
- var ret = new Array();
-
- for (var i = 0; i < str.length; i++) {
- // If the current character is not a backslash,
- // do not modify it.
- if (str[i] != '\\') {
- ret.push(str.charCodeAt(i))
- // If the current character (a backslash) is followed by a
- // second backslash, remove the second backslash;
- // no other modification needed.
- } else if (i+1 < str.length && str[i+1] == '\\') {
- ret.push(str.charCodeAt(i));
- i++;
- // If the backslash is followed by a 3-digit octal number
- // in the range 000 to 377, replace the backslash and
- // numerals by the corresponding octal character
- } else if (i + 3 < str.length && str[i + 1] >= '0' && str[i+1] <= '3' &&
- str[i + 2] >= '0' && str[i+2] <= '7' &&
- str[i + 3] >= '0' && str[i+3] <= '7') {
-
- var sum =
- ((str[i + 1] - '0') * 64) +
- ((str[i + 2] - '0') * 8) +
- ((str[i + 3] - '0'));
-
- // If the octal character is less than 32 decimal,
- // then it is a control (non-printing) character.
- // In this case, dont' de-octalize the input string;
- // immediately return the entire input string.
- if (sum < 32) {
- return str;
- } else {
- ret.push(sum);
- }
-
- i += 3;
- // This clause is reached only if a backslash was encountered,
- // but the backslash was not followed by either another
- // backslash or by 3 valid octal digits. This means that
- // the input string is not a valid octalized string, so we
- // don't know how to de-octalize it. In this case, return
- // the input string.
- } else {
- return str;