parse method

Future<void> parse()

Parses the UCD file line by line and calls the appropriate callback when a Comment, Part or Data is found.

Implementation

Future<void> parse() async {
  if (_ucdStream == null) {
    throw const UcdException('No stream provided');
  }

  await for (var line in _ucdStream!) {
    _row.line++;
    line = line.trim();
    if (line.isEmpty) continue;

    _row
      ..fields.clear()
      ..comment = '';

    if (line[0] == _commentChar) {
      if (onComment != null) onComment?.call(line.substring(1).trim());
      continue;
    }

    if (line.indexOf(_commentChar) > 0) {
      final parts = line.split(_commentChar);
      line = parts[0].trim();
      _row.comment = parts[1].trim();
    }

    if (line[0] == _atChar) {
      if (onPart != null) {
        _row.fields.add(line.substring(1).trim());
        onPart?.call(_row);
      }
      _row.comment = '';
      continue;
    }

    line.split(';').forEach((part) => _row.fields.add(part.trim()));

    _row.getRange(0);
    if (!_row.keepRanges) onData(_row);
  }
}