Skip to content
This repository was archived by the owner on Jul 28, 2024. It is now read-only.

Commit 6a5abb8

Browse files
committed
Add BOM removal string util
1 parent 012d5ad commit 6a5abb8

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/Utils/Strings.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ public static function removeBlankLines(string $s): string
9595
return self::replace($s, "/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n");
9696
}
9797

98+
public static function removeBOM(string $s): string
99+
{
100+
return self::replace($s, "#\xEF\xBB\xBF#", '');
101+
}
102+
98103
public static function removeEmoji(string $s): string
99104
{
100105
foreach (Encoding::EMOJI_PATTERNS as $pattern) {

tests/UtilsTests/StringsTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ public function testRemoveBlankLines(): void
8282
$this->assertEquals("tested\ntext", Strings::removeBlankLines("tested\n \ntext"));
8383
}
8484

85+
public function testRemoveBOM(): void
86+
{
87+
$this->assertEquals('test', Strings::removeBOM("\xEF\xBB\xBFtest"));
88+
}
89+
8590
public function testRemoveEmoji(): void
8691
{
8792
$this->assertEquals('text', Strings::removeEmoji('😀🏯text🗺🎵'));

0 commit comments

Comments
 (0)