mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-19 16:40:26 +02:00
Merge pull request #1318 from disarray2077/patch-1
Add Parse method to Version struct
This commit is contained in:
commit
28dc8741fd
1 changed files with 38 additions and 0 deletions
|
@ -13,6 +13,13 @@ namespace System
|
||||||
Minor = minor;
|
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)
|
public this(uint32 major, uint32 minor, uint32 build, uint32 revision)
|
||||||
{
|
{
|
||||||
Major = major;
|
Major = major;
|
||||||
|
@ -72,5 +79,36 @@ namespace System
|
||||||
((Major == major) && (Minor == minor) && (Build > build)) ||
|
((Major == major) && (Minor == minor) && (Build > build)) ||
|
||||||
((Major == major) && (Minor == minor) && (Build == build) && (Revision >= revision));
|
((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