From 2bd98aedb008de78b965328edf09d1eaf0317fad Mon Sep 17 00:00:00 2001 From: tmeissner Date: Fri, 29 Mar 2013 11:55:56 +0100 Subject: [PATCH] new decodeHTML() function --- scripts/haltestellen.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/scripts/haltestellen.js b/scripts/haltestellen.js index 18a389f..90010d0 100644 --- a/scripts/haltestellen.js +++ b/scripts/haltestellen.js @@ -61,6 +61,24 @@ function ajaxCall(dataUrl, outputElement, callback, responseType) { } +// decode special characters with their utf-8 representation +function decodeHtml(token) { + + var i, + y, + start = [33, 58, 91, 123, 161], + stop = [47, 64, 96, 126, 255], + startLength = start.length; + + for (y = 0; y < startLength; y++) { + for (i = start[y]; i <= stop[y]; i++) { + token = token.replace("&#" + i +";", String.fromCharCode(255)); + } + } + + return token; +} + // wrap all in anonymous function to get out of global scope (function() { @@ -128,9 +146,8 @@ function ajaxCall(dataUrl, outputElement, callback, responseType) { // replace useless chars & split string into array data = data.replace(/\(.+?\)/gi, ''); // remove all content in round parentheses - data = data.replace('ß', 'ss'); // remove some special characters data = data.replace(/<(.+?)>/gi, '$1'); // remove tag parentheses to prevent code injection - data = data.slice(3, -3).split("],["); // split at array boundaries to get an array of arrays + data = data.slice(3, -3).split("],["); // split at array boundaries to get an array of arrays // debug log if (DEBUG === 1) {console.log("parsed data: " + data);} @@ -214,7 +231,6 @@ function ajaxCall(dataUrl, outputElement, callback, responseType) { // replace useless chars & split string into array data = data.replace(/\[\[\[.+?\]\],/gi, '['); // remove useless first city entry data = data.replace(/\(.+?\)/gi, ''); // remove all content in round parentheses - data = data.replace('ß', 'ss'); // remove some special characters data = data.replace(/<(.+?)>/gi, '$1'); // remove tag parentheses to prevent code injection data = data.slice(4, -4).split("],["); // split at array boundaries to get an array of arrays