From a2ab0dce4f0c5ffee0c3439eb6a34f5ab9fee07b Mon Sep 17 00:00:00 2001 From: Xaver Maierhofer Date: Wed, 25 May 2016 23:53:46 +0200 Subject: [PATCH] [TASK] Simple sort for firmware versions --- lib/proportions.js | 8 ++++-- lib/vercomp.js | 68 ---------------------------------------------- 2 files changed, 5 insertions(+), 71 deletions(-) delete mode 100644 lib/vercomp.js diff --git a/lib/proportions.js b/lib/proportions.js index e7b6e56..6bf6390 100644 --- a/lib/proportions.js +++ b/lib/proportions.js @@ -1,5 +1,5 @@ -define(["chroma-js", "virtual-dom", "filters/genericnode", "vercomp"], - function (Chroma, V, Filter, vercomp) { +define(["chroma-js", "virtual-dom", "filters/genericnode"], + function (Chroma, V, Filter) { return function (config, filterManager) { var self = this; @@ -214,7 +214,9 @@ define(["chroma-js", "virtual-dom", "filters/genericnode", "vercomp"], return b[1] - a[1]; })); fillTable("Firmware", fwTable, fwDict.sort(function (a, b) { - return vercomp(b[0], a[0]); + if(b[0] < a[0]) return -1; + if(b[0] > a[0]) return 1; + return 0; })); fillTable("Hardware", hwTable, hwDict.sort(function (a, b) { return b[1] - a[1]; diff --git a/lib/vercomp.js b/lib/vercomp.js deleted file mode 100644 index 4752b11..0000000 --- a/lib/vercomp.js +++ /dev/null @@ -1,68 +0,0 @@ -define([], function () { - function order(c) { - if (/^\d$/.test(c)) { - return 0; - } else if (/^[a-z]$/i.test(c)) { - return c.charCodeAt(0); - } else if (c === "~") { - return -1; - } else if (c) { - return c.charCodeAt(0) + 256; - } else { - return 0; - } - } - - // Based on dpkg code - function vercomp(a, b) { - var apos = 0, bpos = 0; - while (apos < a.length || bpos < b.length) { - var firstDiff = 0; - - while ((apos < a.length && !/^\d$/.test(a[apos])) || (bpos < b.length && !/^\d$/.test(b[bpos]))) { - var ac = order(a[apos]); - var bc = order(b[bpos]); - - if (ac !== bc) { - return ac - bc; - } - - apos++; - bpos++; - } - - while (a[apos] === "0") { - apos++; - } - - while (b[bpos] === "0") { - bpos++; - } - - while (/^\d$/.test(a[apos]) && /^\d$/.test(b[bpos])) { - if (firstDiff === 0) { - firstDiff = a.charCodeAt(apos) - b.charCodeAt(bpos); - } - - apos++; - bpos++; - } - - if (/^\d$/.test(a[apos])) { - return 1; - } - - if (/^\d$/.test(b[bpos])) { - return -1; - } - - if (firstDiff !== 0) { - return firstDiff; - } - } - - return 0; - } - - return vercomp; -});