import 'package:quiver/core.dart'; class ChangelogEntry { final ChangelogVersion version; final String description; final Uri? apkLink; final Uri? linuxLink; final Uri? windowsLink; ChangelogEntry({ required this.version, required this.description, this.apkLink, this.linuxLink, this.windowsLink, }); factory ChangelogEntry.fromTextBlock(String text) { final lines = text.split(RegExp(r'(\r?\n)+')); return ChangelogEntry( version: ChangelogVersion.parse(lines.first), description: lines.skip(1).join('\n'), ); } static List fromTextFile(String text) { final blocks = text.split(RegExp(r'(\r?\n){2}')); return blocks.map(ChangelogEntry.fromTextBlock).toList(); } } class ChangelogVersion implements Comparable { final int major; final int minor; final int patch; final String? prerelease; ChangelogVersion(this.major, this.minor, this.patch, [this.prerelease]); factory ChangelogVersion.parse(String version) { if (version.startsWith('v')) { version = version.substring(1); } String? prerelease; if (version.contains('-')) { final index = version.indexOf('-'); prerelease = version.substring(index + 1); version = version.substring(0, index); } final splitted = version.split('.').map(int.parse).toList(); return ChangelogVersion(splitted[0], splitted[1], splitted[2], prerelease); } @override String toString() { final vString = 'v$major.$minor.$patch'; return prerelease == null ? vString : '$vString-$prerelease'; } @override bool operator==(dynamic other) { if (other is! ChangelogVersion) { return false; } return major == other.major && minor == other.minor && patch == other.patch && prerelease == other.prerelease; } @override int get hashCode { return hash3(major.hashCode, minor.hashCode, patch.hashCode); } @override int compareTo(ChangelogVersion other) { if (major != other.major) { return major.compareTo(other.major); } if (minor != other.minor) { return minor.compareTo(other.minor); } return patch.compareTo(other.patch); } }