lib/parsers.js
function(str) {
  var deliminator_stack = [];
  var length = str.length;
  var i;
  var parts = [];
  var current_part = '';
  var opening_index;
  var closing_index;
  for (i = 0; i < length; i++) {
    opening_index = opening_deliminators.indexOf(str[i]);
    closing_index = closing_deliminators.indexOf(str[i]);
    if (is_space.test(str[i])) {
      if (deliminator_stack.length === 0) {
        if (current_part !== '') {
          parts.push(current_part);
        }
        current_part = '';
      } else {
        current_part += str[i];
      }
    } else {
      if (str[i] === '\\') {
        i++;
        current_part += str[i];
      } else {
        current_part += str[i];
        if (
          closing_index !== -1 &&
          closing_index === deliminator_stack[deliminator_stack.length - 1]
        ) {
          deliminator_stack.pop();
        } else if (opening_index !== -1) {
          deliminator_stack.push(opening_index);
        }
      }
    }
  }
  if (current_part !== '') {
    parts.push(current_part);
  }
  return parts;
}
function(str) {
  var deliminator_stack = [];
  var length = str.length;
  var i;
  var parts = [];
  var current_part = '';
  var opening_index;
  var closing_index;
  for (i = 0; i < length; i++) {
    opening_index = opening_deliminators.indexOf(str[i]);
    closing_index = closing_deliminators.indexOf(str[i]);
    if (is_space.test(str[i])) {
      if (deliminator_stack.length === 0) {
        if (current_part !== '') {
          parts.push(current_part);
        }
        current_part = '';
      } else {
        current_part += str[i];
      }
    } else {
      if (str[i] === '\\') {
        i++;
        current_part += str[i];
      } else {
        current_part += str[i];
        if (
          closing_index !== -1 &&
          closing_index === deliminator_stack[deliminator_stack.length - 1]
        ) {
          deliminator_stack.pop();
        } else if (opening_index !== -1) {
          deliminator_stack.push(opening_index);
        }
      }
    }
  }
  if (current_part !== '') {
    parts.push(current_part);
  }
  return parts;
}
function ( str ) { var deliminator_stack = [ ] ; var length = str . length ; var i ; var parts = [ ] ; var current_part = '' ; var opening_index ; var closing_index ; for ( i = 0 ; i < length ; i ++ ) { opening_index = opening_deliminators . indexOf ( str [ i ] ) ; closing_index = closing_deliminators . indexOf ( str [ i ] ) ; if ( is_space . test ( str [ i ] ) ) { if ( deliminator_stack . length === 0 ) { if ( current_part !== '' ) { parts . push ( current_part ) ; } current_part = '' ; } else { current_part += str [ i ] ; } } else { if ( str [ i ] === '\\' ) { i ++ ; current_part += str [ i ] ; } else { current_part += str [ i ] ; if ( closing_index !== - 1 && closing_index === deliminator_stack [ deliminator_stack . length - 1 ] ) { deliminator_stack . pop ( ) ; } else if ( opening_index !== - 1 ) { deliminator_stack . push ( opening_index ) ; } } } } if ( current_part !== '' ) { parts . push ( current_part ) ; } return parts ; }
this splits on whitespace, but keeps quoted and parened parts together
this splits on whitespace but keeps quoted and parened parts together