diff --git a/src/TUI.Engine/Extensions.cs b/src/TUI.Engine/Extensions.cs index 3f7ed4f..6b1c864 100644 --- a/src/TUI.Engine/Extensions.cs +++ b/src/TUI.Engine/Extensions.cs @@ -40,9 +40,14 @@ public static class Extensions return stringInfo.LengthInTextElements; } + public static string RemoveVersionPrefix(this string version) + { + return version.Replace("^", "").Replace("v", "").Replace("~", ""); + } + public static Version ToVersion(this string textVersion) { - var version = textVersion.Replace("^", "").Replace("v", "").Replace("~", "").Split("."); + var version = textVersion.RemoveVersionPrefix().Split("."); var major = Convert.ToInt32(version[0]); var minor = Convert.ToInt32(version[1]); var patch = Convert.ToInt32(version[2].Split('-')[0]); diff --git a/src/TUI/Domain/Version.cs b/src/TUI/Domain/Version.cs index ed61736..1ebb405 100644 --- a/src/TUI/Domain/Version.cs +++ b/src/TUI/Domain/Version.cs @@ -1,4 +1,5 @@ using TUI.Controls.Components; +using TUI.Engine; namespace TUI.Domain; @@ -8,17 +9,17 @@ public class Version public readonly int Minor; public readonly int Patch; public readonly VersionType Type; - + public Version(string version) { var parts = version.Split('.'); - - Major = Convert.ToInt32(parts[0].Replace("^", "").Replace("~", "")); + + Major = Convert.ToInt32(parts[0].RemoveVersionPrefix()); Minor = Convert.ToInt32(parts[1]); Patch = Convert.ToInt32(string.Join("", parts[2].TakeWhile(char.IsDigit))); - + var extension = parts[2].Replace(Patch.ToString(), ""); - + Type = extension switch { not null when extension.Contains("rc") => VersionType.Candidate,