|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* File containing the {@see AppUtils\ConvertHelper_EOL} class. |
|
4
|
|
|
* |
|
5
|
|
|
* @package Application Utils |
|
6
|
|
|
* @subpackage ConvertHelper |
|
7
|
|
|
* @see AppUtils\ConvertHelper_EOL |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
declare(strict_types=1); |
|
11
|
|
|
|
|
12
|
|
|
namespace AppUtils; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Container class for an end of line (EOL) character. |
|
16
|
|
|
* Used as result when detecting EOL characters in a |
|
17
|
|
|
* string or file. |
|
18
|
|
|
* |
|
19
|
|
|
* @package Application Utils |
|
20
|
|
|
* @subpackage ConvertHelper |
|
21
|
|
|
* @author Sebastian Mordziol <[email protected]> |
|
22
|
|
|
* |
|
23
|
|
|
* @see ConvertHelper::detectEOLCharacter() |
|
24
|
|
|
*/ |
|
25
|
|
|
class ConvertHelper_EOL |
|
26
|
|
|
{ |
|
27
|
|
|
const TYPE_CRLF = 'CR+LF'; |
|
28
|
|
|
const TYPE_LFCR = 'LF+CR'; |
|
29
|
|
|
const TYPE_LF = 'LF'; |
|
30
|
|
|
const TYPE_CR = 'CR'; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $char; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var string |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $type; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @var string |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $description; |
|
46
|
|
|
|
|
47
|
|
|
public function __construct(string $char, string $type, string $description) |
|
48
|
|
|
{ |
|
49
|
|
|
$this->char = $char; |
|
50
|
|
|
$this->type = $type; |
|
51
|
|
|
$this->description = $description; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* The actual EOL character. |
|
56
|
|
|
* @return string |
|
57
|
|
|
*/ |
|
58
|
|
|
public function getCharacter() : string |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->char; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* A more detailed, human readable description of the character. |
|
65
|
|
|
* @return string |
|
66
|
|
|
*/ |
|
67
|
|
|
public function getDescription() : string |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->description; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* The EOL character type, e.g. "CR+LF", "CR"... |
|
74
|
|
|
* @return string |
|
75
|
|
|
* |
|
76
|
|
|
* @see ConvertHelper_EOL::TYPE_CR |
|
77
|
|
|
* @see ConvertHelper_EOL::TYPE_CRLF |
|
78
|
|
|
* @see ConvertHelper_EOL::TYPE_LF |
|
79
|
|
|
* @see ConvertHelper_EOL::TYPE_LFCR |
|
80
|
|
|
*/ |
|
81
|
|
|
public function getType() : string |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->type; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function isCRLF() : bool |
|
87
|
|
|
{ |
|
88
|
|
|
return $this->isType(self::TYPE_CRLF); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function isCR() : bool |
|
92
|
|
|
{ |
|
93
|
|
|
return $this->isType(self::TYPE_CR); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function isLF() : bool |
|
97
|
|
|
{ |
|
98
|
|
|
return $this->isType(self::TYPE_LF); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
public function isLFCR() : bool |
|
102
|
|
|
{ |
|
103
|
|
|
return $this->isType(self::TYPE_LFCR); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function isType(string $type) : bool |
|
107
|
|
|
{ |
|
108
|
|
|
return $this->type === $type; |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|