encode_MACSTRING function

dynamic encode_MACSTRING(
  1. dynamic str,
  2. dynamic encoding
)

Encodes an old-style Macintosh string. Returns a byte array upon success. If the requested encoding is unsupported, or if the input string contains a character that cannot be expressed in the encoding, the function returns 'null'. @param {string} str @param {string} encoding @returns {Array}

Implementation

encode_MACSTRING(str, encoding) {
    // var table = getMacEncodingTable(encoding);
    // if (table == null) {
    //     return null;
    // }

    var result = [];
    // for (var i = 0; i < str.length; i++) {
    //     var c = str.charCodeAt(i);

    //     // In all eight-bit Mac encodings, the characters 0x00..0x7F are
    //     // mapped to U+0000..U+007F; we only need to look up the others.
    //     if (c >= 0x80) {
    //         c = table[c];
    //         if (c == null) {
    //             // str contains a Unicode character that cannot be encoded
    //             // in the requested encoding.
    //             return null;
    //         }
    //     }
    //     result[i] = c;
    //     // result.push(c);
    // }

    return result;
}