parseNameTable function

Map parseNameTable(
  1. dynamic data,
  2. dynamic start,
  3. dynamic ltag
)

Implementation

Map<dynamic, dynamic> parseNameTable(data, start, ltag) {
    Map<dynamic, dynamic> name = {};
    var p = new Parser(data, start);
    var format = p.parseUShort();
    var count = p.parseUShort();
    var stringOffset = p.offset + p.parseUShort();
    for (var i = 0; i < count; i++) {
        var platformID = p.parseUShort();
        var encodingID = p.parseUShort();
        var languageID = p.parseUShort();
        var nameID = p.parseUShort();


        dynamic property;
        if(nameID >= nameTableNames.length) {
          property = nameID;
        } else {
          property = nameTableNames[nameID];
        }


        var byteLength = p.parseUShort();
        var offset = p.parseUShort();
        var language = getLanguageCode(platformID, languageID, ltag);
        var encoding = getEncoding(platformID, encodingID, languageID);
        if (encoding != null && language != null) {
            var text;
            if (encoding == utf16) {
                text = decode_UTF16(data, stringOffset + offset, byteLength);
            } else {
                text = decode_MACSTRING(data, stringOffset + offset, byteLength, encoding);
            }

            if (text != null) {
              var translations = name[property];
              if (translations == null) {
                name[property] = {};
                translations = name[property];
              }

              translations[language] = text;
            }
        }
    }

    var langTagCount = 0;
    if (format == 1) {
        // FIXME: Also handle Microsoft's 'name' table 1.
        langTagCount = p.parseUShort();
    }

    return name;
}