mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-26 17:36:05 -05:00
add any (*
) to ComparableVersionInfo
This commit is contained in:
parent
7d74f16c01
commit
2b1dc178a4
2 changed files with 17 additions and 6 deletions
|
@ -13,6 +13,7 @@ namespace geode {
|
|||
MoreEq,
|
||||
Less,
|
||||
More,
|
||||
Any
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -185,7 +186,7 @@ namespace geode {
|
|||
protected:
|
||||
VersionInfo m_version;
|
||||
VersionCompare m_compare = VersionCompare::Exact;
|
||||
|
||||
|
||||
public:
|
||||
constexpr ComparableVersionInfo() = default;
|
||||
constexpr ComparableVersionInfo(
|
||||
|
@ -196,12 +197,16 @@ 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;
|
||||
}
|
||||
|
||||
// the comparison works invertedly as a version like "v1.2.0"
|
||||
// the comparison works invertedly as a version like "v1.2.0"
|
||||
// should return true for "<=v1.3.0"
|
||||
switch (m_compare) {
|
||||
case VersionCompare::LessEq:
|
||||
|
|
|
@ -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::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::Less: prefix = "<"; break;
|
||||
case VersionCompare::More: prefix = ">"; break;
|
||||
case VersionCompare::Any: return "*";
|
||||
}
|
||||
return prefix + m_version.toString();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue