add any (*) to ComparableVersionInfo

This commit is contained in:
ConfiG 2023-08-07 21:13:40 +03:00
parent 7d74f16c01
commit 2b1dc178a4
No known key found for this signature in database
GPG key ID: 44DA1983F524C11B
2 changed files with 17 additions and 6 deletions

View file

@ -13,6 +13,7 @@ namespace geode {
MoreEq,
Less,
More,
Any
};
/**
@ -196,6 +197,10 @@ namespace geode {
static Result<ComparableVersionInfo> parse(std::string const& string);
constexpr bool compare(VersionInfo const& version) const {
if (m_compare == VersionCompare::Any) {
return true;
}
// opposing major versions never match
if (m_version.getMajor() != version.getMajor()) {
return false;

View file

@ -133,6 +133,11 @@ std::ostream& geode::operator<<(std::ostream& stream, VersionInfo const& version
Result<ComparableVersionInfo> ComparableVersionInfo::parse(std::string const& rawStr) {
VersionCompare compare;
auto string = rawStr;
if (string == "*") {
return Ok(ComparableVersionInfo({0, 0, 0}, VersionCompare::Any));
}
if (string.starts_with("<=")) {
compare = VersionCompare::LessEq;
string.erase(0, 2);
@ -162,13 +167,14 @@ Result<ComparableVersionInfo> ComparableVersionInfo::parse(std::string const& ra
}
std::string ComparableVersionInfo::toString() const {
std::string prefix = "";
std::string prefix;
switch (m_compare) {
case VersionCompare::Exact: prefix = "="; break;
case VersionCompare::LessEq: prefix = "<="; break;
case VersionCompare::MoreEq: prefix = ">="; break;
case VersionCompare::Less: prefix = "<"; break;
case VersionCompare::More: prefix = ">"; break;
case VersionCompare::Any: return "*";
}
return prefix + m_version.toString();
}