diff options
Diffstat (limited to 'web/js/map-OpenLayers.js')
-rw-r--r-- | web/js/map-OpenLayers.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js index 3c9e3fb91..07acf248c 100644 --- a/web/js/map-OpenLayers.js +++ b/web/js/map-OpenLayers.js @@ -27,6 +27,48 @@ $.extend(fixmystreet.utils, { return out.join(','); }, + // https://stackoverflow.com/questions/1293147/javascript-code-to-parse-csv-data/1293163#1293163 + csv_to_array: function( strData, strDelimiter ) { + strDelimiter = (strDelimiter || ","); + + var objPattern = new RegExp( + ( + "(\\" + strDelimiter + "|\\r?\\n|\\r|^)" + + "(?:\"([^\"]*(?:\"\"[^\"]*)*)\"|" + + "([^\"\\" + strDelimiter + "\\r\\n]*))" + ), + "gi" + ); + + var arrData = [[]]; + + var arrMatches = objPattern.exec( strData ); + while (arrMatches) { + + var strMatchedDelimiter = arrMatches[ 1 ]; + + if ( strMatchedDelimiter.length && + strMatchedDelimiter !== strDelimiter) { + arrData.push( [] ); + } + + var strMatchedValue; + if (arrMatches[ 2 ]) { + strMatchedValue = arrMatches[ 2 ].replace( + new RegExp( "\"\"", "g" ), + "\"" + ); + } else { + strMatchedValue = arrMatches[ 3 ]; + } + + arrData[ arrData.length - 1 ].push( strMatchedValue ); + arrMatches = objPattern.exec( strData ); + } + + return( arrData ); + }, + parse_query_string: function() { var qs = {}; if (!location.search) { |