2015-07-08 08:06:43 +00:00
|
|
|
define([], function () {
|
|
|
|
function order(c) {
|
2016-05-22 12:51:30 +00:00
|
|
|
if (/^\d$/.test(c)) {
|
2016-05-22 11:23:43 +00:00
|
|
|
return 0;
|
2016-05-22 12:51:30 +00:00
|
|
|
} else if (/^[a-z]$/i.test(c)) {
|
2016-05-22 11:23:43 +00:00
|
|
|
return c.charCodeAt(0);
|
2016-05-22 12:51:30 +00:00
|
|
|
} else if (c === "~") {
|
2016-05-22 11:23:43 +00:00
|
|
|
return -1;
|
2016-05-22 12:51:30 +00:00
|
|
|
} else if (c) {
|
2016-05-22 11:23:43 +00:00
|
|
|
return c.charCodeAt(0) + 256;
|
2016-05-22 12:51:30 +00:00
|
|
|
} else {
|
2016-05-22 11:23:43 +00:00
|
|
|
return 0;
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2015-07-08 08:06:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Based on dpkg code
|
|
|
|
function vercomp(a, b) {
|
2016-05-22 11:23:43 +00:00
|
|
|
var apos = 0, bpos = 0;
|
2015-07-08 08:06:43 +00:00
|
|
|
while (apos < a.length || bpos < b.length) {
|
2016-05-22 11:23:43 +00:00
|
|
|
var firstDiff = 0;
|
2015-07-08 08:06:43 +00:00
|
|
|
|
|
|
|
while ((apos < a.length && !/^\d$/.test(a[apos])) || (bpos < b.length && !/^\d$/.test(b[bpos]))) {
|
2016-05-22 11:23:43 +00:00
|
|
|
var ac = order(a[apos]);
|
|
|
|
var bc = order(b[bpos]);
|
2015-07-08 08:06:43 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
if (ac !== bc) {
|
2016-05-22 11:23:43 +00:00
|
|
|
return ac - bc;
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2015-07-08 08:06:43 +00:00
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
apos++;
|
|
|
|
bpos++;
|
2015-07-08 08:06:43 +00:00
|
|
|
}
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
while (a[apos] === "0") {
|
2016-05-22 11:23:43 +00:00
|
|
|
apos++;
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2015-07-08 08:06:43 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
while (b[bpos] === "0") {
|
2016-05-22 11:23:43 +00:00
|
|
|
bpos++;
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2015-07-08 08:06:43 +00:00
|
|
|
|
|
|
|
while (/^\d$/.test(a[apos]) && /^\d$/.test(b[bpos])) {
|
2016-05-22 12:51:30 +00:00
|
|
|
if (firstDiff === 0) {
|
2016-05-22 11:23:43 +00:00
|
|
|
firstDiff = a.charCodeAt(apos) - b.charCodeAt(bpos);
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2015-07-08 08:06:43 +00:00
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
apos++;
|
|
|
|
bpos++;
|
2015-07-08 08:06:43 +00:00
|
|
|
}
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
if (/^\d$/.test(a[apos])) {
|
2016-05-22 11:23:43 +00:00
|
|
|
return 1;
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2015-07-08 08:06:43 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
if (/^\d$/.test(b[bpos])) {
|
2016-05-22 11:23:43 +00:00
|
|
|
return -1;
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2015-07-08 08:06:43 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
if (firstDiff !== 0) {
|
2016-05-22 11:23:43 +00:00
|
|
|
return firstDiff;
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2015-07-08 08:06:43 +00:00
|
|
|
}
|
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
return 0;
|
2015-07-08 08:06:43 +00:00
|
|
|
}
|
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
return vercomp;
|
|
|
|
});
|