Sha256: 585912c789578b72e7a39cb142622ecd9dcbfdbd977f3961396736058716a93c

Contents?: true

Size: 1.84 KB

Versions: 31

Compression:

Stored size: 1.84 KB

Contents

d3.csv.parse = function(text) {
  var header;
  return d3.csv.parseRows(text, function(row, i) {
    if (i) {
      var o = {}, j = -1, m = header.length;
      while (++j < m) o[header[j]] = row[j];
      return o;
    } else {
      header = row;
      return null;
    }
  });
};

d3.csv.parseRows = function(text, f) {
  var EOL = {}, // sentinel value for end-of-line
      EOF = {}, // sentinel value for end-of-file
      rows = [], // output rows
      re = /\r\n|[,\r\n]/g, // field separator regex
      n = 0, // the current line number
      t, // the current token
      eol; // is the current token followed by EOL?

  re.lastIndex = 0; // work-around bug in FF 3.6

  /** @private Returns the next token. */
  function token() {
    if (re.lastIndex >= text.length) return EOF; // special case: end of file
    if (eol) { eol = false; return EOL; } // special case: end of line

    // special case: quotes
    var j = re.lastIndex;
    if (text.charCodeAt(j) === 34) {
      var i = j;
      while (i++ < text.length) {
        if (text.charCodeAt(i) === 34) {
          if (text.charCodeAt(i + 1) !== 34) break;
          i++;
        }
      }
      re.lastIndex = i + 2;
      var c = text.charCodeAt(i + 1);
      if (c === 13) {
        eol = true;
        if (text.charCodeAt(i + 2) === 10) re.lastIndex++;
      } else if (c === 10) {
        eol = true;
      }
      return text.substring(j + 1, i).replace(/""/g, "\"");
    }

    // common case
    var m = re.exec(text);
    if (m) {
      eol = m[0].charCodeAt(0) !== 44;
      return text.substring(j, m.index);
    }
    re.lastIndex = text.length;
    return text.substring(j);
  }

  while ((t = token()) !== EOF) {
    var a = [];
    while ((t !== EOL) && (t !== EOF)) {
      a.push(t);
      t = token();
    }
    if (f && !(a = f(a, n++))) continue;
    rows.push(a);
  }

  return rows;
};

Version data entries

31 entries across 31 versions & 2 rubygems

Version Path
picky-statistics-4.5.0 lib/picky-statistics/application/javascripts/d3/src/csv/parse.js
picky-statistics-4.4.2 lib/picky-statistics/application/javascripts/d3/src/csv/parse.js
picky-statistics-4.4.1 lib/picky-statistics/application/javascripts/d3/src/csv/parse.js
picky-statistics-4.4.0 lib/picky-statistics/application/javascripts/d3/src/csv/parse.js
picky-statistics-4.3.2 lib/picky-statistics/application/javascripts/d3/src/csv/parse.js
picky-statistics-4.3.1 lib/picky-statistics/application/javascripts/d3/src/csv/parse.js
picky-statistics-4.3.0 lib/picky-statistics/application/javascripts/d3/src/csv/parse.js
picky-statistics-4.2.4 lib/picky-statistics/application/javascripts/d3/src/csv/parse.js
picky-statistics-4.2.3 lib/picky-statistics/application/javascripts/d3/src/csv/parse.js
picky-statistics-4.2.2 lib/picky-statistics/application/javascripts/d3/src/csv/parse.js
picky-statistics-4.2.1 lib/picky-statistics/application/javascripts/d3/src/csv/parse.js
picky-statistics-4.2.0 lib/picky-statistics/application/javascripts/d3/src/csv/parse.js
picky-statistics-4.1.0 lib/picky-statistics/application/javascripts/d3/src/csv/parse.js
picky-statistics-4.0.9 lib/picky-statistics/application/javascripts/d3/src/csv/parse.js
picky-statistics-4.0.8 lib/picky-statistics/application/javascripts/d3/src/csv/parse.js
picky-statistics-4.0.7 lib/picky-statistics/application/javascripts/d3/src/csv/parse.js
picky-statistics-4.0.6 lib/picky-statistics/application/javascripts/d3/src/csv/parse.js
picky-statistics-4.0.5 lib/picky-statistics/application/javascripts/d3/src/csv/parse.js
picky-statistics-4.0.4 lib/picky-statistics/application/javascripts/d3/src/csv/parse.js
picky-statistics-4.0.3 lib/picky-statistics/application/javascripts/d3/src/csv/parse.js