parse static method

List<ChangelogEntry> parse(
  1. String source
)

Parses source into entries, newest first.

Implementation

static List<ChangelogEntry> parse(String source) {
  final entries = <ChangelogEntry>[];
  ChangelogEntry? current;
  String? currentSection;

  for (final rawLine in source.split('\n')) {
    final line = rawLine.trimRight();
    final header = _versionHeader(line);
    if (header != null) {
      current = ChangelogEntry(
        version: header.version,
        date: header.date,
        title: header.title,
        bullets: [],
        sections: {},
      );
      entries.add(current);
      currentSection = null;
      continue;
    }
    if (current == null) continue;

    final subSection = _sectionHeader(line);
    if (subSection != null) {
      currentSection = subSection;
      current.sections.putIfAbsent(subSection, () => []);
      continue;
    }

    final bullet = _bullet(line);
    if (bullet == null) continue;
    if (currentSection != null) {
      current.sections[currentSection]!.add(bullet);
    }
    current.bullets.add(bullet);
  }
  return entries;
}