1 /*
  2  * ISO2022.js - Implement the various ISO-2022 style mappings
  3  *
  4  * Copyright © 2014-2015, 2018, JEDLSoft
  5  *
  6  * Licensed under the Apache License, Version 2.0 (the "License");
  7  * you may not use this file except in compliance with the License.
  8  * You may obtain a copy of the License at
  9  *
 10  *     http://www.apache.org/licenses/LICENSE-2.0
 11  *
 12  * Unless required by applicable law or agreed to in writing, software
 13  * distributed under the License is distributed on an "AS IS" BASIS,
 14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  *
 16  * See the License for the specific language governing permissions and
 17  * limitations under the License.
 18  */
 19 
 20 var Charset = require("./Charset.js");
 21 var Charmap = require("./Charmap.js");
 22 
 23 /**
 24  * @class
 25  * Create a new ISO-2022 mapping instance
 26  *
 27  * @constructor
 28  */
 29 var ISO2022 = function (options) {
 30     // first, load in all the tables we need for this version of 2022
 31     options = options || {sync: true};
 32     var name = options.name || "ISO-2022-JP";
 33     var sync = typeof(options.sync) === "boolean" ? options.sync : true;
 34 
 35     if (typeof(options.charset) === "object" && options.charset instanceof Charset) {
 36         this.charset = options.charset;
 37         if (typeof(options.onLoad) === "function") {
 38             options.onLoad(this);
 39         }
 40     } else {
 41         new Charset({
 42             name: name,
 43             sync: sync,
 44             loadParams: options.loadParams,
 45             onLoad: ilib.bind(this, function(cs) {
 46                 this.charset = cs;
 47                 if (typeof(options.onLoad) === "function") {
 48                     options.onLoad(this);
 49                 }
 50             })
 51         });
 52     }
 53 };
 54 
 55 ISO2022.prototype = new Charmap({noinstance: true});
 56 ISO2022.prototype.parent = Charmap;
 57 ISO2022.prototype.constructor = ISO2022;
 58 
 59 ISO2022.prototype.mapToUnicode = function (bytes) {
 60     // TODO: implement ISO 2022 mappings
 61 };
 62 
 63 ISO2022.prototype.mapToNative = function(str) {
 64     // TODO: implement ISO 2022 mappings
 65 };
 66 
 67 /*
 68 Still in development
 69 
 70 Charmap._algorithms["ISO-2022-JP"] = Charmap.ISO2022;
 71 Charmap._algorithms["ISO-2022-JP-1"] = Charmap.ISO2022;
 72 Charmap._algorithms["ISO-2022-JP-2"] = Charmap.ISO2022;
 73 Charmap._algorithms["ISO-2022-JP-3"] = Charmap.ISO2022;
 74 Charmap._algorithms["ISO-2022-JP-2004"] = Charmap.ISO2022;
 75 Charmap._algorithms["ISO-2022-CN"] = Charmap.ISO2022;
 76 Charmap._algorithms["ISO-2022-CN-EXT"] = Charmap.ISO2022;
 77 Charmap._algorithms["ISO-2022-KR"] = Charmap.ISO2022;
 78 */
 79 
 80 module.exports = ISO2022;