|
|
|
@ -878,7 +878,7 @@
@@ -878,7 +878,7 @@
|
|
|
|
|
_delimiterError = false; |
|
|
|
|
if (!_config.delimiter) |
|
|
|
|
{ |
|
|
|
|
var delimGuess = guessDelimiter(input, _config.newline); |
|
|
|
|
var delimGuess = guessDelimiter(input, _config.newline, _config.skipEmptyLines); |
|
|
|
|
if (delimGuess.successful) |
|
|
|
|
_config.delimiter = delimGuess.bestDelimiter; |
|
|
|
|
else |
|
|
|
@ -1040,7 +1040,7 @@
@@ -1040,7 +1040,7 @@
|
|
|
|
|
return _results; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function guessDelimiter(input, newline) |
|
|
|
|
function guessDelimiter(input, newline, skipEmptyLines) |
|
|
|
|
{ |
|
|
|
|
var delimChoices = [',', '\t', '|', ';', Papa.RECORD_SEP, Papa.UNIT_SEP]; |
|
|
|
|
var bestDelim, bestDelta, fieldCountPrevRow; |
|
|
|
@ -1048,7 +1048,7 @@
@@ -1048,7 +1048,7 @@
|
|
|
|
|
for (var i = 0; i < delimChoices.length; i++) |
|
|
|
|
{ |
|
|
|
|
var delim = delimChoices[i]; |
|
|
|
|
var delta = 0, avgFieldCount = 0; |
|
|
|
|
var delta = 0, avgFieldCount = 0, emptyLinesCount = 0; |
|
|
|
|
fieldCountPrevRow = undefined; |
|
|
|
|
|
|
|
|
|
var preview = new Parser({ |
|
|
|
@ -1059,6 +1059,10 @@
@@ -1059,6 +1059,10 @@
|
|
|
|
|
|
|
|
|
|
for (var j = 0; j < preview.data.length; j++) |
|
|
|
|
{ |
|
|
|
|
if (skipEmptyLines && preview.data[j].length === 1 && preview.data[j][0].length === 0) { |
|
|
|
|
emptyLinesCount++ |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
var fieldCount = preview.data[j].length; |
|
|
|
|
avgFieldCount += fieldCount; |
|
|
|
|
|
|
|
|
@ -1075,7 +1079,7 @@
@@ -1075,7 +1079,7 @@
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (preview.data.length > 0) |
|
|
|
|
avgFieldCount /= preview.data.length; |
|
|
|
|
avgFieldCount /= (preview.data.length - emptyLinesCount); |
|
|
|
|
|
|
|
|
|
if ((typeof bestDelta === 'undefined' || delta < bestDelta) |
|
|
|
|
&& avgFieldCount > 1.99) |
|
|
|
|