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