Skip to content

Commit

Permalink
BOM stripping no longer depends on mbstring extension
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Jan 19, 2024
1 parent 0ff3919 commit 468a22b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 3 additions & 5 deletions src/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
use function array_unique;
use function is_array;
use function iterator_count;
use function mb_strlen;
use function mb_substr;
use function strlen;
use function substr;

Expand Down Expand Up @@ -113,7 +111,7 @@ protected function setHeader(int $offset): array

$header = $this->removeBOM(
$header,
!$this->is_input_bom_included ? mb_strlen($this->getInputBOM()) : 0,
!$this->is_input_bom_included ? strlen($this->getInputBOM()) : 0,
$this->enclosure
);

Expand Down Expand Up @@ -190,7 +188,7 @@ protected function removeBOM(array $record, int $bom_length, string $enclosure):
return $record;
}

$record[0] = mb_substr($record[0], $bom_length);
$record[0] = substr($record[0], $bom_length);
if ($enclosure.$enclosure !== substr($record[0].$record[0], strlen($record[0]) - 1, 2)) {
return $record;
}
Expand Down Expand Up @@ -463,7 +461,7 @@ protected function stripBOM(Iterator $iterator, string $bom): Iterator
return $iterator;
}

$bom_length = mb_strlen($bom);
$bom_length = strlen($bom);
$mapper = function (array $record, int $index) use ($bom_length): array {
if (0 !== $index) {
return $record;
Expand Down
2 changes: 1 addition & 1 deletion src/ReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public function testStripBOM(array $record, string $expected_bom, string $expect
fputcsv($fp, $record);
$csv = Reader::createFromStream($fp);
self::assertSame($expected_bom, $csv->getInputBOM());
foreach ($csv as $offset => $row) {
foreach ($csv as $row) {
self::assertSame($expected, $row[0]);
}
$csv = null;
Expand Down

0 comments on commit 468a22b

Please sign in to comment.