Skip to content

Instantly share code, notes, and snippets.

@dom96
Created April 6, 2012 20:56
Show Gist options
  • Save dom96/2322864 to your computer and use it in GitHub Desktop.
Save dom96/2322864 to your computer and use it in GitHub Desktop.
import algorithm, strutils
proc cmpPlatforms(a, b: string): int =
if a == b: return 0
var dashes = a.split('-')
var dashes2 = b.split('-')
if dashes[0] == dashes2[0]:
if dashes[1] == dashes2[1]: return system.cmp(a,b)
case dashes[1]
of "x86":
return 1
of "x86_64":
if dashes2[1] == "x86": return -1
else: return 1
of "ppc64":
if dashes2[1] == "x86" or dashes2[1] == "x86_64": return -1
else: return 1
else:
return system.cmp(dashes[1], dashes2[1])
else:
case dashes[0]
of "linux":
return 1
of "windows":
if dashes2[0] == "linux": return -1
else: return 1
of "macosx":
if dashes2[0] == "linux" or dashes2[0] == "windows": return -1
else: return 1
else: return system.cmp(a, b)
when isMainModule:
var pf: seq[string] = @["macosx-x86-1058", "linux-x86", "windows-x86",
"linux-ppc64", "linux-x86_64", "macosx-x86-1068"]
echo cmpPlatforms("linux-x86", "linux-ppc64")
echo cmpPlatforms("linux-ppc64", "linux-x86")
echo cmpPlatforms("macosx-x86-1058", "macosx-x86-1048")
pf.sort(cmpPlatforms, Descending)
echo(repr(pf))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment