decodeListArray function
List<Object?>
decodeListArray(
- ArrayHeaderInfo header,
- LineCursor cursor,
- int baseDepth,
- ResolvedDecodeOptions options,
Decodes a list array
Implementation
List<Object?> decodeListArray(
ArrayHeaderInfo header,
LineCursor cursor,
int baseDepth,
ResolvedDecodeOptions options,
) {
final items = <Object?>[];
final itemDepth = baseDepth + 1;
// Track line range for blank line validation
int? startLine;
int? endLine;
while (!cursor.atEnd() && items.length < header.length) {
final line = cursor.peek();
if (line == null || line.depth < itemDepth) {
break;
}
if (line.depth == itemDepth && line.content.startsWith(listItemPrefix)) {
// Track first and last item line numbers
startLine ??= line.lineNumber;
endLine = line.lineNumber;
final item = decodeListItem(cursor, itemDepth, header.delimiter, options);
items.add(item);
// Update endLine to the current cursor position (after item was decoded)
final currentLine = cursor.current();
if (currentLine != null) {
endLine = currentLine.lineNumber;
}
} else {
break;
}
}
assertExpectedCount(items.length, header.length, 'list array items', options);
// In strict mode, check for blank lines inside the array
if (options.strict && startLine != null && endLine != null) {
validateNoBlankLinesInRange(
startLine, // From first item line
endLine, // To last item line
cursor.getBlankLines(),
options.strict,
'list array',
);
}
// In strict mode, check for extra items
if (options.strict) {
validateNoExtraListItems(cursor, itemDepth, header.length);
}
return items;
}