-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from jabranr/bugfix-trim-spaces
Bugfix trim spaces
- Loading branch information
Showing
3 changed files
with
69 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
* Parse CSV data from a file, path, stream, resource or string | ||
* | ||
* @author: Jabran Rafique <[email protected]> | ||
* @version: 2.1.0 | ||
* @version: 2.1.1 | ||
* @license: MIT License | ||
* @link: https://github.com/jabranr/csv-parser | ||
*/ | ||
|
@@ -136,6 +136,7 @@ public function setHeaders($headers = null) { | |
throw new InvalidDataException('Unexpected headers data.'); | ||
} | ||
|
||
$headers = $this->trimRecursively($headers); | ||
$this->headers = $headers; | ||
return $this; | ||
} | ||
|
@@ -166,10 +167,29 @@ public function setColumns($columns = null) { | |
throw new InvalidDataException('Unexpected columns data.'); | ||
} | ||
|
||
$columns = $this->trimRecursively($columns); | ||
$this->columns = $columns; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Trim data recursively | ||
* | ||
* @param mixed $data | ||
* @return mixed | ||
*/ | ||
public function trimRecursively($data) { | ||
if (!is_string($data) && !is_array($data)) { | ||
return $data; | ||
} | ||
|
||
if (is_string($data)) { | ||
return trim($data); | ||
} | ||
|
||
return array_map(array($this, 'trimRecursively'), $data); | ||
} | ||
|
||
/** | ||
* Get columns | ||
* | ||
|
@@ -196,6 +216,7 @@ public function setRows($rows = null) { | |
throw new InvalidDataException('Unexpected rows data.'); | ||
} | ||
|
||
$rows = $this->trimRecursively($rows); | ||
$this->rows = $rows; | ||
return $this; | ||
} | ||
|
@@ -394,7 +415,7 @@ private function _makeRowsWithHeaders() { | |
// Ignore rows that do not have same length | ||
if ( count($this->getHeaders()) !== count($row) ) { | ||
continue; | ||
} | ||
} | ||
|
||
$rowsWithHeader[] = array_combine($this->getHeaders(), $row); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters