Skip to content

Commit d9e659b

Browse files
authored
Update Application.php
1 parent 2e21375 commit d9e659b

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

src/Application.php

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,32 @@ public function fixFiles()
7474

7575
private function getFileDominantLineEnding(string $file)
7676
{
77-
$n = preg_match_all('/(?<!\r)\n/', $file);
78-
$rn = preg_match_all('/(?<=\r)\n/i', $file);
79-
80-
if ($rn > $n) {
81-
return "\r\n";
77+
static $eols = array(
78+
"\0x000D000A", // [UNICODE] CR+LF: CR (U+000D) followed by LF (U+000A)
79+
"\0x000A", // [UNICODE] LF: Line Feed, U+000A
80+
"\0x000B", // [UNICODE] VT: Vertical Tab, U+000B
81+
"\0x000C", // [UNICODE] FF: Form Feed, U+000C
82+
"\0x000D", // [UNICODE] CR: Carriage Return, U+000D
83+
"\0x0085", // [UNICODE] NEL: Next Line, U+0085
84+
"\0x2028", // [UNICODE] LS: Line Separator, U+2028
85+
"\0x2029", // [UNICODE] PS: Paragraph Separator, U+2029
86+
"\0x0D0A", // [ASCII] CR+LF: Windows, TOPS-10, RT-11, CP/M, MP/M, DOS, Atari TOS, OS/2, Symbian OS, Palm OS
87+
"\0x0A0D", // [ASCII] LF+CR: BBC Acorn, RISC OS spooled text output.
88+
"\0x0A", // [ASCII] LF: Multics, Unix, Unix-like, BeOS, Amiga, RISC OS
89+
"\0x0D", // [ASCII] CR: Commodore 8-bit, BBC Acorn, TRS-80, Apple II, Mac OS <=v9, OS-9
90+
"\0x1E", // [ASCII] RS: QNX (pre-POSIX)
91+
//"\0x76", // [?????] NEWLINE: ZX80, ZX81 [DEPRECATED]
92+
"\0x15", // [EBCDEIC] NEL: OS/390, OS/400
93+
);
94+
$cur_cnt = 0;
95+
$cur_eol = "\n";
96+
foreach($eols as $eol){
97+
if(($count = substr_count($file, $eol)) > $cur_cnt){
98+
$cur_cnt = $count;
99+
$cur_eol = $eol;
100+
}
82101
}
83-
84-
return "\n";
102+
return $cur_eol;
85103
}
86104

87105
private function getDocBodyIdent(string $doc)

0 commit comments

Comments
 (0)