temporary CSV fix?

upd4.2
Michael Aschauer 2018-09-17 11:53:04 +02:00
rodzic 73d70bec70
commit e2c44f26e3
1 zmienionych plików z 21 dodań i 1 usunięć

Wyświetl plik

@ -2743,7 +2743,7 @@ Process.prototype.parseCSV = function (string) {
// by lines.
// taken from:
// https://stackoverflow.com/questions/8493195/how-can-i-parse-a-csv-string-with-javascript-which-contains-comma-in-data
/*
var re_valid = /^\s*(?:'[^'\\]*(?:\\[\S\s][^'\\]*)*'|"[^"\\]*(?:\\[\S\s][^"\\]*)*"|[^,'"\s\\]*(?:\s+[^,'"\s\\]+)*)\s*(?:,\s*(?:'[^'\\]*(?:\\[\S\s][^'\\]*)*'|"[^"\\]*(?:\\[\S\s][^"\\]*)*"|[^,'"\s\\]*(?:\s+[^,'"\s\\]+)*)\s*)*$/,
re_value = /(?!\s*$)\s*(?:'([^'\\]*(?:\\[\S\s][^'\\]*)*)'|"([^"\\]*(?:\\[\S\s][^"\\]*)*)"|([^,'"\s\\]*(?:\s+[^,'"\s\\]+)*))\s*(?:,|$)/g,
a = [];
@ -2771,6 +2771,26 @@ Process.prototype.parseCSV = function (string) {
a.push('');
}
return new List(a);
*/
let ret = [''], i = 0, p = '', s = true;
for (let l in string) {
l = string[l];
if ('"' === l) {
s = !s;
if ('"' === p) {
ret[i] += '"';
l = '-';
} el
l = '-';
} else if (s && ',' === l)
l = ret[++i] = '';
else
ret[i] += l;
p = l;
}
return new List(ret);
};
// Process debugging