mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-19 08:30:25 +02:00
Add Parse method to Version struct
This commit is contained in:
parent
af8bd5a813
commit
a306890146
1 changed files with 38 additions and 0 deletions
|
@ -12,6 +12,13 @@ namespace System
|
|||
Major = major;
|
||||
Minor = minor;
|
||||
}
|
||||
|
||||
public this(uint32 major, uint32 minor, uint32 build)
|
||||
{
|
||||
Major = major;
|
||||
Minor = minor;
|
||||
Build = build;
|
||||
}
|
||||
|
||||
public this(uint32 major, uint32 minor, uint32 build, uint32 revision)
|
||||
{
|
||||
|
@ -72,5 +79,36 @@ namespace System
|
|||
((Major == major) && (Minor == minor) && (Build > build)) ||
|
||||
((Major == major) && (Minor == minor) && (Build == build) && (Revision >= revision));
|
||||
}
|
||||
|
||||
public static Result<Version> Parse(StringView version)
|
||||
{
|
||||
var components = version.Split('.');
|
||||
|
||||
mixin ParseComponent(var component)
|
||||
{
|
||||
uint32 parsedComponent;
|
||||
if (!(uint32.Parse(component) case .Ok(out parsedComponent)))
|
||||
return .Err;
|
||||
parsedComponent
|
||||
}
|
||||
|
||||
let major = ParseComponent!(components.GetNext());
|
||||
let minor = ParseComponent!(components.GetNext());
|
||||
|
||||
if (!components.HasMore)
|
||||
return Version(major, minor);
|
||||
|
||||
let build = ParseComponent!(components.GetNext());
|
||||
|
||||
if (!components.HasMore)
|
||||
return Version(major, minor, build);
|
||||
|
||||
let revision = ParseComponent!(components.GetNext());
|
||||
|
||||
if (!components.HasMore)
|
||||
return Version(major, minor, build, revision);
|
||||
|
||||
return .Err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue