updated parser regex (after basic unit tests)

This commit is contained in:
Mottie 2012-12-14 14:09:37 -06:00
parent 0ac192d791
commit f9d1d2bab2

View File

@ -14,11 +14,12 @@
* @author Christian Bach/christian.bach@polyester.se
* @contributor Rob Garrison/https://github.com/Mottie/tablesorter
*/
/*jshint browser:true, jquery:true, unused:false */
/*jshint browser:true, jquery:true, unused:false, expr: true */
/*global console:false, alert:false */
!(function($) {
"use strict";
$.extend({
/*jshint supernew:true */
tablesorter: new function() {
var ts = this;
@ -693,6 +694,7 @@
// no closest in jQuery v1.2.6 - tbdy = $tb.index( $(cell).closest('tbody') ),$row = $(cell).closest('tr');
tbdy = $tb.index( $(cell).parents('tbody').filter(':last') ),
$row = $(cell).parents('tr').filter(':last');
cell = $(cell)[0]; // in case cell is a jQuery object
// tbody may not exist if update is initialized while tbody is removed for processing
if ($tb.length && tbdy >= 0) {
row = $tb.eq(tbdy).find('tr').index( $row );
@ -960,19 +962,20 @@
// used when replacing accented characters during sorting
ts.characterEquivalents = {
"a" : "\u00e1\u00e0\u00e2\u00e3\u00e4", // áàâãä
"A" : "\u00c1\u00c0\u00c2\u00c3\u00c4", // ÁÀÂÃÄ
"c" : "\u00e7", // ç
"C" : "\u00c7", // Ç
"e" : "\u00e9\u00e8\u00ea\u00eb", // éèêë
"E" : "\u00c9\u00c8\u00ca\u00cb", // ÉÈÊË
"i" : "\u00ed\u00ec\u0130\u00ee\u00ef", // íìİîï
"a" : "\u00e1\u00e0\u00e2\u00e3\u00e4\u0105\u00e5", // áàâãäąå
"A" : "\u00c1\u00c0\u00c2\u00c3\u00c4\u0104\u00c5", // ÁÀÂÃÄĄÅ
"c" : "\u00e7\u0107\u010d", // çćč
"C" : "\u00c7\u0106\u010c", // ÇĆČ
"e" : "\u00e9\u00e8\u00ea\u00eb\u011b\u0119", // éèêëěę
"E" : "\u00c9\u00c8\u00ca\u00cb\u011a\u0118", // ÉÈÊËĚĘ
"i" : "\u00ed\u00ec\u0130\u00ee\u00ef\u0131", // íìİîïı
"I" : "\u00cd\u00cc\u0130\u00ce\u00cf", // ÍÌİÎÏ
"o" : "\u00f3\u00f2\u00f4\u00f5\u00f6", // óòôõö
"O" : "\u00d3\u00d2\u00d4\u00d5\u00d6", // ÓÒÔÕÖ
"S" : "\u00df", // ß
"u" : "\u00fa\u00f9\u00fb\u00fc", // úùûü
"U" : "\u00da\u00d9\u00db\u00dc" // ÚÙÛÜ
"ss": "\u00df", // ß (s sharp)
"SS": "\u1e9e", // ẞ (Capital sharp s)
"u" : "\u00fa\u00f9\u00fb\u00fc\u016f", // úùûüů
"U" : "\u00da\u00d9\u00db\u00dc\u016e" // ÚÙÛÜŮ
};
ts.replaceAccents = function(s) {
var a, acc = '[', eq = ts.characterEquivalents;
@ -1133,7 +1136,7 @@
ts.isDigit = function(s) {
// replace all unwanted chars and match
return isNaN(s) ? (/^[\-+(]?\d+[)]?$/).test(s.toString().replace(/[,.'\s]/g, '')) : true;
return isNaN(s) ? (/^[\-+(]?\d+[)]?$/).test(s.toString().replace(/[,.'"\s]/g, '')) : true;
};
}()
@ -1164,7 +1167,7 @@
ts.addParser({
id: "currency",
is: function(s) {
return (/^\(?[\u00a3$\u20ac\u00a4\u00a5\u00a2?.]\d+/).test(s); // £$€¤¥¢
return (/^\(?\d+[\u00a3$\u20ac\u00a4\u00a5\u00a2?.]|[\u00a3$\u20ac\u00a4\u00a5\u00a2?.]\d+\)?$/).test(s); // £$€¤¥¢
},
format: function(s, table) {
return ts.formatFloat(s.replace(/[^\w,. \-()]/g, ""), table);
@ -1214,7 +1217,7 @@
ts.addParser({
id: "percent",
is: function(s) {
return (/\d%\)?$/).test(s);
return (/(\d\s?%|%\s?\d)/).test(s);
},
format: function(s, table) {
return ts.formatFloat(s.replace(/%/g, ""), table);
@ -1225,7 +1228,8 @@
ts.addParser({
id: "usLongDate",
is: function(s) {
return (/^[A-Z]{3,10}\.?\s+\d{1,2},?\s+(\d{4}|'?\d{2})\s+(([0-2]?\d:[0-5]\d)|([0-1]?\d:[0-5]\d\s?([AP]M)))$/i).test(s);
// two digit years are not allowed cross-browser
return (/^[A-Z]{3,10}\.?\s+\d{1,2},?\s+(\d{4})(\s+\d{1,2}:\d{2}(:\d{2})?(\s+[AP]M)?)?$/i).test(s);
},
format: function(s, table) {
return ts.formatFloat( (new Date(s.replace(/(\S)([AP]M)$/i, "$1 $2")).getTime() || ''), table);
@ -1236,8 +1240,8 @@
ts.addParser({
id: "shortDate", // "mmddyyyy", "ddmmyyyy" or "yyyymmdd"
is: function(s) {
// testing for ####-##-#### - so it's not perfect
return (/^(\d{2}|\d{4})[\/\-\,\.\s+]\d{2}[\/\-\.\,\s+](\d{2}|\d{4})$/).test(s);
// testing for ####-##-####, so it's not perfect
return (/^(\d{1,2}|\d{4})[\/\-\,\.\s+]\d{1,2}[\/\-\.\,\s+](\d{1,2}|\d{4})$/).test(s);
},
format: function(s, table, cell, cellIndex) {
var c = table.config, ci = c.headerList[cellIndex],