decode_MACSTRING function

dynamic decode_MACSTRING(
  1. dynamic dataView,
  2. dynamic offset,
  3. dynamic dataLength,
  4. dynamic encoding,
)

Decodes an old-style Macintosh string. Returns either a Unicode JavaScript string, or 'null' if the encoding is unsupported. For example, we do not support Chinese, Japanese or Korean because these would need large mapping tables. @param {DataView} dataView @param {number} offset @param {number} dataLength @param {string} encoding @returns {string}

Implementation

decode_MACSTRING(dataView, offset, dataLength, encoding) {
    var table = eightBitMacEncodings[encoding];
    if (table == null) {
        return null;
    }

    var result = '';
    for (var i = 0; i < dataLength; i++) {
        var c = dataView.getUint8(offset + 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 <= 0x7F) {
            result += String.fromCharCode(c);
        } else {
            result += table[c & 0x7F];
        }
    }

    return result;
}