using System; using System.Collections.Generic; using System.Text.RegularExpressions; namespace Unity.VisualScripting { public struct SemanticVersion : IComparable { [Serialize] public readonly int major; [Serialize] public readonly int minor; [Serialize] public readonly int patch; [Serialize] public readonly string label; [Serialize] public readonly int increment; public SemanticVersion(int major, int minor, int patch, string label, int increment) { this.major = major; this.minor = minor; this.patch = patch; this.label = label; this.increment = increment; } public SemanticVersion(string semVerString) { this = Parse(semVerString); } public SemanticLabel semanticLabel { get { if (StringUtility.IsNullOrWhiteSpace(label)) { return SemanticLabel.Unspecified; } switch (label.Filter(whitespace: false, punctuation: false, symbols: false).ToLower()) { case "pre": return SemanticLabel.Pre; case "a": case "alpha": return SemanticLabel.Alpha; case "b": case "beta": return SemanticLabel.Beta; case "rc": case "releasecandidate": return SemanticLabel.ReleaseCandidate; case "f": case "final": case "hotfix": case "fix": return SemanticLabel.Final; default: return SemanticLabel.Unspecified; } } } public override string ToString() { if (semanticLabel == SemanticLabel.Unspecified) { return $"{major}.{minor}.{patch}"; } else { return $"{major}.{minor}.{patch}{label}{increment}"; } } public static implicit operator SemanticVersion(string s) { return Parse(s); } public static SemanticVersion Parse(string s) { SemanticVersion result; if (!TryParse(s, out result)) { throw new ArgumentException("s"); } return result; } public static bool TryParse(string s, out SemanticVersion result) { result = default(SemanticVersion); if (s == null) { throw new ArgumentNullException(nameof(s)); } var regex = new Regex(@"(?\d+)\.(?\d+)\.(?\d+)(?:(?