From 468a22b06eaf681fe2dd738e9d06c0e5e8ac5d13 Mon Sep 17 00:00:00 2001 From: ignace nyamagana butera Date: Fri, 19 Jan 2024 21:25:13 +0100 Subject: [PATCH] BOM stripping no longer depends on mbstring extension --- src/Reader.php | 8 +++----- src/ReaderTest.php | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Reader.php b/src/Reader.php index b7eeba82..e4a4359e 100644 --- a/src/Reader.php +++ b/src/Reader.php @@ -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; @@ -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 ); @@ -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; } @@ -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; diff --git a/src/ReaderTest.php b/src/ReaderTest.php index 95b12e09..af0fdc6b 100644 --- a/src/ReaderTest.php +++ b/src/ReaderTest.php @@ -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;