@@ -74,14 +74,32 @@ public function fixFiles()
74
74
75
75
private function getFileDominantLineEnding (string $ file )
76
76
{
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
+ }
82
101
}
83
-
84
- return "\n" ;
102
+ return $ cur_eol ;
85
103
}
86
104
87
105
private function getDocBodyIdent (string $ doc )
0 commit comments