1 | <?php |
||
7 | final class EOL { |
||
8 | /** |
||
9 | * Carriage return: Mac OS <=v9, OS-9, Apple II, Commodore 8-bit, BBC Acorn, TRS-80. |
||
10 | */ |
||
11 | const EOL_CR = "\r"; |
||
12 | /** |
||
13 | * Line feed: Unix, Unix-like, Multics, BeOS, Amiga, RISC OS. |
||
14 | */ |
||
15 | const EOL_LF = "\n"; |
||
16 | /** |
||
17 | * Carriage return/Line feed: Windows, TOPS-10, RT-11, CP/M, MP/M, DOS, Atari TOS, OS/2, Symbian OS, Palm OS. |
||
18 | */ |
||
19 | const EOL_CR_LF = "\r\n"; |
||
20 | |||
21 | /** |
||
22 | * Note that EOL::detect depends on this order. |
||
23 | * |
||
24 | * @var array |
||
25 | */ |
||
26 | private static $eols = [ |
||
27 | "\r\n" => [ |
||
28 | 'CR+LF', |
||
29 | 'Carriage return/line feed: Windows, TOPS-10, RT-11, CP/M, MP/M, DOS, Atari TOS, OS/2, Symbian OS, Palm OS', |
||
30 | ], |
||
31 | "\n" => ['LF', 'Line feed: Unix, Unix-like, Multics, BeOS, Amiga, RISC OS'], |
||
32 | "\r" => [ |
||
33 | 'CR', |
||
34 | 'Carriage return: Mac OS <=v9, OS-9, Apple II, Commodore 8-bit, BBC Acorn, TRS-80', |
||
35 | ], |
||
36 | ]; |
||
37 | private $eol; |
||
38 | private $name; |
||
39 | private $description; |
||
40 | |||
41 | /** |
||
42 | * @param string $eol Line ending. See the EOL_* class constants. |
||
43 | */ |
||
44 | public function __construct($eol) { |
||
53 | |||
54 | /** |
||
55 | * __toString casts to/returns the raw line ending string. |
||
56 | * |
||
57 | * @return string |
||
58 | */ |
||
59 | public function __toString() { |
||
62 | |||
63 | /** |
||
64 | * getName of line ending, e.g. `LF`. |
||
65 | * |
||
66 | * @return string |
||
67 | */ |
||
68 | public function getName() { |
||
71 | |||
72 | /** |
||
73 | * getDescription of line ending, e.g. `Line feed: Unix, Unix-like, Multics, BeOS, Amiga, RISC OS`. |
||
74 | * |
||
75 | * @return string |
||
76 | */ |
||
77 | public function getDescription() { |
||
80 | |||
81 | /** |
||
82 | * Apply this EOL style to a string. |
||
83 | * |
||
84 | * @param string $input Input to be converted. |
||
85 | * |
||
86 | * @return string |
||
87 | */ |
||
88 | public function apply($input) { |
||
91 | |||
92 | /** |
||
93 | * Detect the EOL style of a string and return an EOL representation. |
||
94 | * |
||
95 | * @param string $input Input string to be analyzed. |
||
96 | * |
||
97 | * @throws \RuntimeException Thrown on failure to detect any line ending. |
||
98 | * |
||
99 | * @return \nochso\Omni\EOL |
||
100 | */ |
||
101 | public static function detect($input) { |
||
109 | |||
110 | /** |
||
111 | * DetectDefault falls back to a default EOL style on failure. |
||
112 | * |
||
113 | * @param string $input Input string to be analyzed. |
||
114 | * @param string $default Optional, defaults to "\n". The default line ending to use when $strict is false. See the `EOL::EOL_*` constants. |
||
115 | * |
||
116 | * @return \nochso\Omni\EOL |
||
117 | */ |
||
118 | public static function detectDefault($input, $default = self::EOL_LF) { |
||
126 | } |
||
127 |