Skip to content

Commit

Permalink
Bug Fix detectDelimiterList by adding COUNT_RECURSIVE
Browse files Browse the repository at this point in the history
Discussion see #55

At the moment detectDelimiterList method doesn't find the correct delimiter when there are 2 or more potential delimiters in the csv line. For example if there are 30 semicolons (;) and only one comma (,) in the checked csv line the method doesn't find the correct delimiter anymore and returns only both found occurences (";" and ",").

This is because fetchRowsCountByDelimiter method (when we use default $nb_rows = 1 value) always prints 1 for both found delimiters as a result regardless if there are 30 semicolons and only one comma there.

So I added the COUNT_RECURSIVE mode in fetchRowsCountByDelimiter method in order we get a relation how often a delimiter is present in the line(s).

In the detectDelimiterList method we can then change the return line so it only returns the delimiter with the most occurences. To make that even more robust we return only one delimiter if it's occurence is way higher then the occurence of the 2nd found delimiter (I choosed 2.5x the times here). If its quantity is not way higher we return all found delimiters like it is now.
Heart1010 authored and nyamsprod committed Nov 7, 2014
1 parent 54c594e commit c14b04f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/Config/Controls.php
Original file line number Diff line number Diff line change
@@ -109,7 +109,7 @@ protected function fetchRowsCountByDelimiter($delimiter, $nb_rows = 1)
return is_array($row) && count($row) > 1;
});

return count(iterator_to_array($iterator, false));
return count(iterator_to_array($iterator, false), COUNT_RECURSIVE);
}

/**

0 comments on commit c14b04f

Please sign in to comment.