lib/jquery.csv-0.71.js
function(csv, options) {
        // cache settings
        var separator = options.separator;
        var delimiter = options.delimiter;
        
        // set initial state if it's missing
        if(!options.state.rowNum) {
          options.state.rowNum = 1;
        }
        if(!options.state.colNum) {
          options.state.colNum = 1;
        }

        // clear initial state
        var entry = [];
        var state = 0;
        var value = '';

        function endOfValue() {
          if(options.onParseValue === undefined) {
            // onParseValue hook not set
            entry.push(value);
          } else {
            var hook = options.onParseValue(value, options.state); // onParseValue Hook
            // false skips the value, configurable through a hook
            if(hook !== false) {
              entry.push(hook);
            }
          }
          // reset the state
          value = '';
          state = 0;
          // update global state
          options.state.colNum++;
        }

        // checked for a cached regEx first
        if(!options.match) {
          // escape regex-specific control chars
          var escSeparator = RegExp.escape(separator);
          var escDelimiter = RegExp.escape(delimiter);
          
          // compile the regEx str using the custom delimiter/separator
          var match = /(D|S|\n|\r|[^DS\r\n]+)/;
          var matchSrc = match.source;
          matchSrc = matchSrc.replace(/S/g, escSeparator);
          matchSrc = matchSrc.replace(/D/g, escDelimiter);
          options.match = RegExp(matchSrc, 'gm');
        }

        // put on your fancy pants...
        // process control chars individually, use look-ahead on non-control chars
        csv.replace(options.match, function (m0) {
          switch (state) {
            // the start of a value
            case 0:
              // null last value
              if (m0 === separator) {
                value += '';
                endOfValue();
                break;
              }
              // opening delimiter
              if (m0 === delimiter) {
                state = 1;
                break;
              }
              // skip un-delimited new-lines
              if (m0 === '\n' || m0 === '\r') {
                break;
              }
              // un-delimited value
              value += m0;
              state = 3;
              break;

            // delimited input
            case 1:
              // second delimiter? check further
              if (m0 === delimiter) {
                state = 2;
                break;
              }
              // delimited data
              value += m0;
              state = 1;
              break;

            // delimiter found in delimited input
            case 2:
              // escaped delimiter?
              if (m0 === delimiter) {
                value += m0;
                state = 1;
                break;
              }
              // null value
              if (m0 === separator) {
                endOfValue();
                break;
              }
              // skip un-delimited new-lines
              if (m0 === '\n' || m0 === '\r') {
                break;
              }
              // broken paser?
              throw new Error('CSVDataError: Illegal State [Row:' + options.state.rowNum + '][Col:' + options.state.colNum + ']');

            // un-delimited input
            case 3:
              // null last value
              if (m0 === separator) {
                endOfValue();
                break;
              }
              // skip un-delimited new-lines
              if (m0 === '\n' || m0 === '\r') {
                break;
              }
              // non-compliant data
              if (m0 === delimiter) {
                throw new Error('CSVDataError: Illegal Quote [Row:' + options.state.rowNum + '][Col:' + options.state.colNum + ']');
              }
              // broken parser?
              throw new Error('CSVDataError: Illegal Data [Row:' + options.state.rowNum + '][Col:' + options.state.colNum + ']');
            default:
              // shenanigans
              throw new Error('CSVDataError: Unknown State [Row:' + options.state.rowNum + '][Col:' + options.state.colNum + ']');
          }
          //console.log('val:' + m0 + ' state:' + state);
        });

        // submit the last value
        endOfValue();

        return entry;
      }
function(csv, options) {
        // cache settings
        var separator = options.separator;
        var delimiter = options.delimiter;
        
        // set initial state if it's missing
        if(!options.state.rowNum) {
          options.state.rowNum = 1;
        }
        if(!options.state.colNum) {
          options.state.colNum = 1;
        }

        // clear initial state
        var entry = [];
        var state = 0;
        var value = '';

        function endOfValue() {
          if(options.onParseValue === undefined) {
            // onParseValue hook not set
            entry.push(value);
          } else {
            var hook = options.onParseValue(value, options.state); // onParseValue Hook
            // false skips the value, configurable through a hook
            if(hook !== false) {
              entry.push(hook);
            }
          }
          // reset the state
          value = '';
          state = 0;
          // update global state
          options.state.colNum++;
        }

        // checked for a cached regEx first
        if(!options.match) {
          // escape regex-specific control chars
          var escSeparator = RegExp.escape(separator);
          var escDelimiter = RegExp.escape(delimiter);
          
          // compile the regEx str using the custom delimiter/separator
          var match = /(D|S|\n|\r|[^DS\r\n]+)/;
          var matchSrc = match.source;
          matchSrc = matchSrc.replace(/S/g, escSeparator);
          matchSrc = matchSrc.replace(/D/g, escDelimiter);
          options.match = RegExp(matchSrc, 'gm');
        }

        // put on your fancy pants...
        // process control chars individually, use look-ahead on non-control chars
        csv.replace(options.match, function (m0) {
          switch (state) {
            // the start of a value
            case 0:
              // null last value
              if (m0 === separator) {
                value += '';
                endOfValue();
                break;
              }
              // opening delimiter
              if (m0 === delimiter) {
                state = 1;
                break;
              }
              // skip un-delimited new-lines
              if (m0 === '\n' || m0 === '\r') {
                break;
              }
              // un-delimited value
              value += m0;
              state = 3;
              break;

            // delimited input
            case 1:
              // second delimiter? check further
              if (m0 === delimiter) {
                state = 2;
                break;
              }
              // delimited data
              value += m0;
              state = 1;
              break;

            // delimiter found in delimited input
            case 2:
              // escaped delimiter?
              if (m0 === delimiter) {
                value += m0;
                state = 1;
                break;
              }
              // null value
              if (m0 === separator) {
                endOfValue();
                break;
              }
              // skip un-delimited new-lines
              if (m0 === '\n' || m0 === '\r') {
                break;
              }
              // broken paser?
              throw new Error('CSVDataError: Illegal State [Row:' + options.state.rowNum + '][Col:' + options.state.colNum + ']');

            // un-delimited input
            case 3:
              // null last value
              if (m0 === separator) {
                endOfValue();
                break;
              }
              // skip un-delimited new-lines
              if (m0 === '\n' || m0 === '\r') {
                break;
              }
              // non-compliant data
              if (m0 === delimiter) {
                throw new Error('CSVDataError: Illegal Quote [Row:' + options.state.rowNum + '][Col:' + options.state.colNum + ']');
              }
              // broken parser?
              throw new Error('CSVDataError: Illegal Data [Row:' + options.state.rowNum + '][Col:' + options.state.colNum + ']');
            default:
              // shenanigans
              throw new Error('CSVDataError: Unknown State [Row:' + options.state.rowNum + '][Col:' + options.state.colNum + ']');
          }
          //console.log('val:' + m0 + ' state:' + state);
        });

        // submit the last value
        endOfValue();

        return entry;
      }
function ( csv , options ) { // cache settings var separator = options . separator ; var delimiter = options . delimiter ; // set initial state if it's missing if ( ! options . state . rowNum ) { options . state . rowNum = 1 ; } if ( ! options . state . colNum ) { options . state . colNum = 1 ; } // clear initial state var entry = [ ] ; var state = 0 ; var value = '' ; function endOfValue ( ) { if ( options . onParseValue === undefined ) { // onParseValue hook not set entry . push ( value ) ; } else { var hook = options . onParseValue ( value , options . state ) ; // onParseValue Hook // false skips the value, configurable through a hook if ( hook !== false ) { entry . push ( hook ) ; } } // reset the state value = '' ; state = 0 ; // update global state options . state . colNum ++ ; } // checked for a cached regEx first if ( ! options . match ) { // escape regex-specific control chars var escSeparator = RegExp . escape ( separator ) ; var escDelimiter = RegExp . escape ( delimiter ) ; // compile the regEx str using the custom delimiter/separator var match = / (D|S|\n|\r|[^DS\r\n]+) / ; var matchSrc = match . source ; matchSrc = matchSrc . replace ( / S / g , escSeparator ) ; matchSrc = matchSrc . replace ( / D / g , escDelimiter ) ; options . match = RegExp ( matchSrc , 'gm' ) ; } // put on your fancy pants... // process control chars individually, use look-ahead on non-control chars csv . replace ( options . match , function ( m0 ) { switch ( state ) { // the start of a value case 0 : // null last value if ( m0 === separator ) { value += '' ; endOfValue ( ) ; break ; } // opening delimiter if ( m0 === delimiter ) { state = 1 ; break ; } // skip un-delimited new-lines if ( m0 === '\n' || m0 === '\r' ) { break ; } // un-delimited value value += m0 ; state = 3 ; break ; // delimited input case 1 : // second delimiter? check further if ( m0 === delimiter ) { state = 2 ; break ; } // delimited data value += m0 ; state = 1 ; break ; // delimiter found in delimited input case 2 : // escaped delimiter? if ( m0 === delimiter ) { value += m0 ; state = 1 ; break ; } // null value if ( m0 === separator ) { endOfValue ( ) ; break ; } // skip un-delimited new-lines if ( m0 === '\n' || m0 === '\r' ) { break ; } // broken paser? throw new Error ( 'CSVDataError: Illegal State [Row:' + options . state . rowNum + '][Col:' + options . state . colNum + ']' ) ; // un-delimited input case 3 : // null last value if ( m0 === separator ) { endOfValue ( ) ; break ; } // skip un-delimited new-lines if ( m0 === '\n' || m0 === '\r' ) { break ; } // non-compliant data if ( m0 === delimiter ) { throw new Error ( 'CSVDataError: Illegal Quote [Row:' + options . state . rowNum + '][Col:' + options . state . colNum + ']' ) ; } // broken parser? throw new Error ( 'CSVDataError: Illegal Data [Row:' + options . state . rowNum + '][Col:' + options . state . colNum + ']' ) ; default : // shenanigans throw new Error ( 'CSVDataError: Unknown State [Row:' + options . state . rowNum + '][Col:' + options . state . colNum + ']' ) ; } //console.log('val:' + m0 + ' state:' + state); } ) ; // submit the last value endOfValue ( ) ; return entry ; }
a csv entry parser
a csv entry parser