I need to replace accented characters in a string with their unaccented counterparts and I implemented this http://lehelk.com/2011/05/06/script-to-remove-diacritics/.
var defaultDiacriticsRemovalMap = [
{'base':'A', 'letters':/[\u0041\u24B6\uFF21\u00C0\u00C1\u00C2\u1EA6\u1EA4\u1EAA\u1EA8\u00C3\u0100\u0102\u1EB0\u1EAE\u1EB4\u1EB2\u0226\u01E0\u00C4\u01DE\u1EA2\u00C5\u01FA\u01CD\u0200\u0202\u1EA0\u1EAC\u1EB6\u1E00\u0104\u023A\u2C6F]/g},
/* ...
so on and so forth
.... */
];
var changes;
function removeDiacritics (str) {
if(!changes) {
changes = defaultDiacriticsRemovalMap;
}
for(var i=0; i<changes.length; i++) {
str = str.replace(changes[i].letters, changes[i].base);
}
return str.replace(/\s+/g, '_'); //space to dash
}
This fails in IE 7 and 8 (works in every other browser) with the error 'changes[...].letters' is null or not an object on the line str = str.replace(changes[i].letters, changes[i].base);, and I have no idea why. I mean, I understand that the browser thinks that it had encountered a null value, but I fail to see how can this be the case.
I copied my code to a jsfiddle (it fires the same error there as well) so you can take a look at it.