diff options
Diffstat (limited to 'source/core/slang-semantic-version.cpp')
| -rw-r--r-- | source/core/slang-semantic-version.cpp | 76 |
1 files changed, 46 insertions, 30 deletions
diff --git a/source/core/slang-semantic-version.cpp b/source/core/slang-semantic-version.cpp index 9e68de746..ab7b5007b 100644 --- a/source/core/slang-semantic-version.cpp +++ b/source/core/slang-semantic-version.cpp @@ -1,15 +1,18 @@ // slang-semantic-version.cpp #include "slang-semantic-version.h" -#include "slang-com-helper.h" - #include "../core/slang-string-util.h" +#include "slang-com-helper.h" -namespace Slang { +namespace Slang +{ // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! SemanticVersion !!!!!!!!!!!!!!!!!!!!!!!!!!!!! -SlangResult SemanticVersion::parse(const UnownedStringSlice& value, char separatorChar, SemanticVersion& outVersion) +SlangResult SemanticVersion::parse( + const UnownedStringSlice& value, + char separatorChar, + SemanticVersion& outVersion) { outVersion.reset(); @@ -21,7 +24,7 @@ SlangResult SemanticVersion::parse(const UnownedStringSlice& value, char separat return SLANG_FAIL; } - Int ints[3] = { 0, 0, 0 }; + Int ints[3] = {0, 0, 0}; for (Index i = 0; i < splitCount; i++) { SLANG_RETURN_ON_FAIL(StringUtil::parseInt(slices[i], ints[i])); @@ -40,7 +43,7 @@ SlangResult SemanticVersion::parse(const UnownedStringSlice& value, char separat return SLANG_OK; } -SlangResult SemanticVersion::parse(const UnownedStringSlice& value, SemanticVersion& outVersion) +SlangResult SemanticVersion::parse(const UnownedStringSlice& value, SemanticVersion& outVersion) { return parse(value, '.', outVersion); } @@ -54,7 +57,7 @@ void SemanticVersion::append(StringBuilder& buf) const } } -/* static */SemanticVersion SemanticVersion::getEarliest(const ThisType* versions, Count count) +/* static */ SemanticVersion SemanticVersion::getEarliest(const ThisType* versions, Count count) { if (count <= 0) { @@ -72,7 +75,7 @@ void SemanticVersion::append(StringBuilder& buf) const return bestVersion; } -/* static */SemanticVersion SemanticVersion::getLatest(const ThisType* versions, Count count) +/* static */ SemanticVersion SemanticVersion::getLatest(const ThisType* versions, Count count) { if (count <= 0) { @@ -92,7 +95,10 @@ void SemanticVersion::append(StringBuilder& buf) const // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! MatchSemanticVersion !!!!!!!!!!!!!!!!!!!!!!!!!!!!! -/* static */SemanticVersion MatchSemanticVersion::findAnyBest(const SemanticVersion* versions, Count count, const ThisType& matchVersion) +/* static */ SemanticVersion MatchSemanticVersion::findAnyBest( + const SemanticVersion* versions, + Count count, + const ThisType& matchVersion) { // If there aren't any we are done if (count <= 0) @@ -111,48 +117,58 @@ void SemanticVersion::append(StringBuilder& buf) const switch (matchVersion.m_kind) { - case Kind::Past: + case Kind::Past: { return SemanticVersion::getEarliest(versions, count); } - case Kind::Unknown: - case Kind::Future: + case Kind::Unknown: + case Kind::Future: { // If it's unknown, we just get the latest return SemanticVersion::getLatest(versions, count); } - case Kind::Major: + case Kind::Major: { start = SemanticVersion(matchVersion.m_version.m_major, 0, 0); end = SemanticVersion(matchVersion.m_version.m_major + 1, 0, 0); break; } - case Kind::MajorMinor: + case Kind::MajorMinor: { - start = SemanticVersion(matchVersion.m_version.m_major, matchVersion.m_version.m_minor, 0); - end = SemanticVersion(matchVersion.m_version.m_major, matchVersion.m_version.m_minor + 1, 0); + start = + SemanticVersion(matchVersion.m_version.m_major, matchVersion.m_version.m_minor, 0); + end = SemanticVersion( + matchVersion.m_version.m_major, + matchVersion.m_version.m_minor + 1, + 0); break; } - case Kind::MajorMinorPatch: + case Kind::MajorMinorPatch: { start = SemanticVersion(matchVersion.m_version); - end = SemanticVersion(matchVersion.m_version.m_major, matchVersion.m_version.m_minor, matchVersion.m_version.m_patch + 1); + end = SemanticVersion( + matchVersion.m_version.m_major, + matchVersion.m_version.m_minor, + matchVersion.m_version.m_patch + 1); break; } - default: break; + default: break; } List<SemanticVersion> sortedVersions; sortedVersions.addRange(versions, count); // Sort into increasing values - sortedVersions.sort([&](const SemanticVersion& a, const SemanticVersion& b) -> bool { return a < b; }); + sortedVersions.sort( + [&](const SemanticVersion& a, const SemanticVersion& b) -> bool { return a < b; }); Index startIndex = 0; - for (; startIndex < count && sortedVersions[startIndex] < start; ++startIndex); + for (; startIndex < count && sortedVersions[startIndex] < start; ++startIndex) + ; Index endIndex = startIndex; - for (; endIndex < count && sortedVersions[endIndex] < end; ++endIndex); + for (; endIndex < count && sortedVersions[endIndex] < end; ++endIndex) + ; // If we have a span of versions, get the last in the span if (startIndex < endIndex) @@ -173,7 +189,7 @@ void SemanticVersion::append(StringBuilder& buf) const return sortedVersions[startIndex - 1]; } - // All cases should be covered, but return the last one + // All cases should be covered, but return the last one return sortedVersions[count - 1]; } @@ -181,21 +197,21 @@ void MatchSemanticVersion::append(StringBuilder& buf) const { switch (m_kind) { - default: - case Kind::Unknown: buf << "unknown"; break; - case Kind::Past: buf << "past"; break; - case Kind::Future: buf << "future"; break; - case Kind::Major: + default: + case Kind::Unknown: buf << "unknown"; break; + case Kind::Past: buf << "past"; break; + case Kind::Future: buf << "future"; break; + case Kind::Major: { buf << m_version.m_major; break; } - case Kind::MajorMinor: + case Kind::MajorMinor: { buf << m_version.m_major << "." << m_version.m_minor; break; } - case Kind::MajorMinorPatch: + case Kind::MajorMinorPatch: { m_version.append(buf); break; |
