add modrinth pre-release support to flexVer implementation

extended the flexVer implementation to consider any space that is after
a numeric section as a pre-release.

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2026-04-01 19:16:29 +03:00
parent 5a0931d3cf
commit 8427626e56
No known key found for this signature in database
GPG key ID: 55EF5DA53DB36318
2 changed files with 33 additions and 5 deletions

View file

@ -107,9 +107,11 @@ void Version::parse()
if (c == '+') {
break; // Ignore appendices
}
if (c == '-') {
// custom: the space is special to handle the strings like "1.20 Pre-Release 1"
// this is needed to support Modrinth versions
if (c == '-' || c == ' ') {
// Add dash to component
cur.value += '-';
cur.value += c;
i++;
// If the next rune is non-digit, mark as pre-release (requires >= 1 non-digit after dash so the component has length > 1)
if (i < len && !m_string.at(i).isDigit()) {
@ -121,8 +123,9 @@ void Version::parse()
}
for (; i < len; i++) {
auto r = m_string.at(i);
if ((r.isDigit() != (cur.t == Section::Type::Numeric)) ||
(r == '-' && cur.t != Section::Type::PreRelease) // "---" is a valid pre-release component
if ((r.isDigit() != (cur.t == Section::Type::Numeric)) // starts a new section
|| (r == ' ' && cur.t == Section::Type::Numeric) // custom: numeric section then a space is a pre-release
|| (r == '-' && cur.t != Section::Type::PreRelease) // "---" is a valid pre-release component
|| r == '+') {
// Run completed (do not consume this rune)
break;