parseListOfLists method

dynamic parseListOfLists(
  1. dynamic itemCallback
)

Parse a list of offsets to lists of 16-bit integers, or a list of offsets to lists of offsets to any kind of items. If itemCallback is not provided, a list of list of UShort is assumed. If provided, itemCallback is called on each item and must parse the item. See examples in tables/gsub.js

Implementation

parseListOfLists(itemCallback) {
    var offsets = this.parseOffset16List(null);
    var count = offsets.length;
    var relativeOffset = this.relativeOffset;
    var list = List<List?>.filled(count, []);
    for (var i = 0; i < count; i++) {
        var start = offsets[i];
        if (start == 0) {
            // NULL offset
            // Add i as owned property to list. Convenient with assert.
            list[i] = null;
            continue;
        }
        this.relativeOffset = start;
        if (itemCallback) {
            var subOffsets = this.parseOffset16List(null);
            var subList = List.filled(subOffsets.length, null);
            for (var j = 0; j < subOffsets.length; j++) {
                this.relativeOffset = start + subOffsets[j];
                subList[j] = itemCallback.call(this);
            }
            list[i] = subList;
        } else {
            list[i] = this.parseUShortList(null);
        }
    }
    this.relativeOffset = relativeOffset;
    return list;
}