1
d3.csv.parse = function(text) {
3
return d3.csv.parseRows(text, function(row, i) {
5
var o = {}, j = -1, m = header.length;
6
while (++j < m) o[header[j]] = row[j];
15
d3.csv.parseRows = function(text, f) {
16
var EOL = {}, // sentinel value for end-of-line
17
EOF = {}, // sentinel value for end-of-file
18
rows = [], // output rows
19
re = /\r\n|[,\r\n]/g, // field separator regex
20
n = 0, // the current line number
21
t, // the current token
22
eol; // is the current token followed by EOL?
24
re.lastIndex = 0; // work-around bug in FF 3.6
26
/** @private Returns the next token. */
28
if (re.lastIndex >= text.length) return EOF; // special case: end of file
29
if (eol) { eol = false; return EOL; } // special case: end of line
31
// special case: quotes
33
if (text.charCodeAt(j) === 34) {
35
while (i++ < text.length) {
36
if (text.charCodeAt(i) === 34) {
37
if (text.charCodeAt(i + 1) !== 34) break;
42
var c = text.charCodeAt(i + 1);
45
if (text.charCodeAt(i + 2) === 10) re.lastIndex++;
46
} else if (c === 10) {
49
return text.substring(j + 1, i).replace(/""/g, "\"");
53
var m = re.exec(text);
55
eol = m[0].charCodeAt(0) !== 44;
56
return text.substring(j, m.index);
58
re.lastIndex = text.length;
59
return text.substring(j);
62
while ((t = token()) !== EOF) {
64
while ((t !== EOL) && (t !== EOF)) {
68
if (f && !(a = f(a, n++))) continue;