mirror of
https://github.com/parsecsv/parsecsv-for-php.git
synced 2026-02-19 08:36:39 +00:00
Improved PHPDoc of _check_count; Refactored vars in _guess_delimiter
This commit does not contain functional changes.
This commit is contained in:
@@ -1005,10 +1005,10 @@ class parseCSV {
|
|||||||
* Check if passed info might be delimiter
|
* Check if passed info might be delimiter
|
||||||
* Only used by find_delimiter
|
* Only used by find_delimiter
|
||||||
*
|
*
|
||||||
* @param [type] $char [description]
|
* @param string $char Potential field separating character
|
||||||
* @param array $array
|
* @param array $array Frequency
|
||||||
* @param int $depth
|
* @param int $depth Number of analyzed rows
|
||||||
* @param [type] $preferred [description]
|
* @param string $preferred Preferred delimiter characters
|
||||||
*
|
*
|
||||||
* @return string|false special string used for delimiter selection, or false
|
* @return string|false special string used for delimiter selection, or false
|
||||||
*/
|
*/
|
||||||
@@ -1148,8 +1148,9 @@ class parseCSV {
|
|||||||
$chars = [];
|
$chars = [];
|
||||||
$strlen = strlen($data);
|
$strlen = strlen($data);
|
||||||
$enclosed = false;
|
$enclosed = false;
|
||||||
$n = 1;
|
$current_row = 1;
|
||||||
$to_end = true;
|
$to_end = true;
|
||||||
|
$pattern = '/[' . preg_quote($this->auto_non_chars, '/') . ']/i';
|
||||||
|
|
||||||
// walk specific depth finding possible delimiter characters
|
// walk specific depth finding possible delimiter characters
|
||||||
for ($i = 0; $i < $strlen; $i++) {
|
for ($i = 0; $i < $strlen; $i++) {
|
||||||
@@ -1167,27 +1168,27 @@ class parseCSV {
|
|||||||
|
|
||||||
// end of row
|
// end of row
|
||||||
} elseif (($ch == "\n" && $pch != "\r" || $ch == "\r") && !$enclosed) {
|
} elseif (($ch == "\n" && $pch != "\r" || $ch == "\r") && !$enclosed) {
|
||||||
if ($n >= $search_depth) {
|
if ($current_row >= $search_depth) {
|
||||||
$strlen = 0;
|
$strlen = 0;
|
||||||
$to_end = false;
|
$to_end = false;
|
||||||
} else {
|
} else {
|
||||||
$n++;
|
$current_row++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// count character
|
// count character
|
||||||
} elseif (!$enclosed) {
|
} elseif (!$enclosed) {
|
||||||
if (!preg_match('/[' . preg_quote($this->auto_non_chars, '/') . ']/i', $ch)) {
|
if (!preg_match($pattern, $ch)) {
|
||||||
if (!isset($chars[$ch][$n])) {
|
if (!isset($chars[$ch][$current_row])) {
|
||||||
$chars[$ch][$n] = 1;
|
$chars[$ch][$current_row] = 1;
|
||||||
} else {
|
} else {
|
||||||
$chars[$ch][$n]++;
|
$chars[$ch][$current_row]++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// filtering
|
// filtering
|
||||||
$depth = $to_end ? $n - 1 : $n;
|
$depth = $to_end ? $current_row - 1 : $current_row;
|
||||||
$filtered = [];
|
$filtered = [];
|
||||||
foreach ($chars as $char => $value) {
|
foreach ($chars as $char => $value) {
|
||||||
if ($match = $this->_check_count($char, $value, $depth, $preferred)) {
|
if ($match = $this->_check_count($char, $value, $depth, $preferred)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user