Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/StringUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ public static function removeZeroWidthCharacters(string $input): string
return \Safe\preg_replace('/[\x{200B}-\x{200D}\x{FEFF}]/u', '', $input);
}

/** Replaces line breaks with spaces and collapses consecutive whitespace into one space. */
public static function replaceLineBreaksWithSpaces(string $input): string
{
$withoutLineBreaks = str_replace([self::WINDOWS_NEWLINE, "\r", "\n"], ' ', $input);

return \Safe\preg_replace('/\s+/', ' ', $withoutLineBreaks);
}

/** Convert string that could be in different UTF encodings (UTF-8, UTF-16BE, ...) to UTF-8. */
public static function toUTF8(string $string): string
{
Expand Down
8 changes: 8 additions & 0 deletions tests/StringUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ public function testRemoveZeroWidthCharacters(): void
);
}

public function testReplaceLineBreaksWithSpaces(): void
{
self::assertSame(
'Befund: unauffällig Empfehlung: Kontrolle',
StringUtil::replaceLineBreaksWithSpaces("Befund:\r\nunauffällig\n\nEmpfehlung: \rKontrolle")
);
}

public function testUTF8(): void
{
$expectedUTF8 = 'test';
Expand Down
Loading