cache natural sort regex

This commit is contained in:
Mottie 2014-03-03 18:25:43 -06:00
parent 5d91d5e81a
commit 7269aadc74

View File

@ -1155,6 +1155,8 @@
// regex used in natural sort
ts.regex = {
chunk : /(^([+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?)?$|^0x[0-9a-f]+$|\d+)/gi, // chunk/tokenize numbers & letters
schunk: /^\\0/, // start chunk
echunk: /\\0$/, // end chunk
hex: /^0x[0-9a-f]+$/i // hex
};
@ -1171,8 +1173,8 @@
if ( xD > yD ) { return 1; }
}
// chunk/tokenize
xN = a.replace(r.chunk, '\\0$1\\0').replace(/\\0$/, '').replace(/^\\0/, '').split('\\0');
yN = b.replace(r.chunk, '\\0$1\\0').replace(/\\0$/, '').replace(/^\\0/, '').split('\\0');
xN = a.replace(r.chunk, '\\0$1\\0').replace(r.echunk, '').replace(r.schunk, '').split('\\0');
yN = b.replace(r.chunk, '\\0$1\\0').replace(r.echunk, '').replace(r.schunk, '').split('\\0');
mx = Math.max(xN.length, yN.length);
// natural sorting through split numeric strings and default strings
for (i = 0; i < mx; i++) {