Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
Support more types of versions
Browse files Browse the repository at this point in the history
  • Loading branch information
dz0ny committed Apr 30, 2024
1 parent fdee704 commit ed5773c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Pareto Updater/Extensions/String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ extension String {
version = version.replacingOccurrences(of: ".-", with: "-")
version = version.replacingOccurrences(of: "release", with: "")
version = version.replacingOccurrences(of: "version", with: "")
version = version.replacingOccurrences(of: "(", with: "")
version = version.replacingOccurrences(of: ")", with: "")
version = version.replacingOccurrences(of: "v", with: "")
return version
}
Expand All @@ -29,11 +31,14 @@ extension String {
var versionComponents = components(separatedBy: versionDelimiter) // <1>
var otherVersionComponents = otherVersion.components(separatedBy: versionDelimiter)

let zeroDiff = versionComponents.count - otherVersionComponents.count // <2>
let numbersOnly = replacingOccurrences(of: versionDelimiter, with: "")
let otherNumbersOnly = otherVersion.replacingOccurrences(of: versionDelimiter, with: "")

let zeroDiff = numbersOnly.count - otherNumbersOnly.count // <2>

if zeroDiff == 0 { // <3>
// Same format, compare normally
return compare(otherVersion, options: .numeric)
return numbersOnly.compare(otherNumbersOnly, options: .numeric)
} else {
let zeros = Array(repeating: "0", count: abs(zeroDiff)) // <4>
if zeroDiff > 0 {
Expand Down

0 comments on commit ed5773c

Please sign in to comment.