ts3phpframework
Loading...
Searching...
No Matches
Char.php
Go to the documentation of this file.
1
<?php
2
3
namespace
PlanetTeamSpeak\TeamSpeak3Framework\Helper
;
4
5
use
PlanetTeamSpeak\TeamSpeak3Framework\Exception\HelperException
;
6
13
class
Char
14
{
20
protected
string
$char
;
21
28
public
function
__construct
(
string
$char
)
29
{
30
if
(strlen(
$char
) != 1) {
31
throw
new
HelperException
(
"char parameter may not contain more or less than one character"
);
32
}
33
34
$this->
char
= $char;
35
}
36
42
public
function
isLetter
(): bool
43
{
44
return
ctype_alpha($this->
char
);
45
}
46
52
public
function
isDigit
(): bool
53
{
54
return
ctype_digit($this->
char
);
55
}
56
62
public
function
isSpace
(): bool
63
{
64
return
ctype_space($this->
char
);
65
}
66
72
public
function
isMark
(): bool
73
{
74
return
ctype_punct($this->
char
);
75
}
76
82
public
function
isControl
(): bool
83
{
84
return
ctype_cntrl($this->
char
);
85
}
86
92
public
function
isPrintable
(): bool
93
{
94
return
ctype_print($this->
char
);
95
}
96
102
public
function
isNull
(): bool
103
{
104
return
$this->
char
===
"\0"
;
105
}
106
112
public
function
isUpper
(): bool
113
{
114
return
$this->
char
=== strtoupper($this->
char
);
115
}
116
122
public
function
isLower
(): bool
123
{
124
return
$this->
char
=== strtolower($this->
char
);
125
}
126
133
public
function
toUpper
():
Char
134
{
135
return
($this->
isUpper
()) ? $this :
new
self
(strtoupper($this));
136
}
137
144
public
function
toLower
():
Char
145
{
146
return
($this->
isLower
()) ? $this :
new
self
(strtolower($this));
147
}
148
154
public
function
toAscii
(): int
155
{
156
return
ord($this->
char
);
157
}
158
164
public
function
toUnicode
(): int
165
{
166
$h = ord($this->
char
[0]);
167
168
if
($h <= 0x7F) {
169
return
$h;
170
} elseif ($h < 0xC2) {
171
return
false
;
172
} elseif ($h <= 0xDF) {
173
return
($h & 0x1F) << 6 | (ord($this->
char
[1]) & 0x3F);
174
} elseif ($h <= 0xEF) {
175
return
($h & 0x0F) << 12 | (ord($this->
char
[1]) & 0x3F) << 6 | (ord($this->
char
[2]) & 0x3F);
176
} elseif ($h <= 0xF4) {
177
return
($h & 0x0F) << 18 | (ord($this->
char
[1]) & 0x3F) << 12 | (ord($this->
char
[2]) & 0x3F) << 6 | (ord($this->
char
[3]) & 0x3F);
178
}
else
{
179
return
-1;
180
}
181
}
182
188
public
function
toHex
(): string
189
{
190
return
strtoupper(dechex($this->
toAscii
()));
191
}
192
200
public
static
function
fromHex
(
string
$hex):
Char
201
{
202
if
(strlen($hex) != 2) {
203
throw
new
HelperException
(
"given parameter '"
. $hex .
"' is not a valid hexadecimal number"
);
204
}
205
206
return
new
self
(chr(hexdec($hex)));
207
}
208
214
public
function
toString
(): string
215
{
216
return
$this->char
;
217
}
218
224
public
function
toInt
(): int
225
{
226
return
intval($this->
char
);
227
}
228
234
public
function
__toString
()
235
{
236
return
$this->char
;
237
}
238
}
PlanetTeamSpeak\TeamSpeak3Framework\Exception\HelperException
Enhanced exception class for PlanetTeamSpeak\TeamSpeak3Framework\Helper* objects.
Definition
HelperException.php:12
PlanetTeamSpeak\TeamSpeak3Framework\Helper\Char
Helper class for char handling.
Definition
Char.php:14
PlanetTeamSpeak\TeamSpeak3Framework\Helper\Char\isPrintable
isPrintable()
Definition
Char.php:92
PlanetTeamSpeak\TeamSpeak3Framework\Helper\Char\toInt
toInt()
Definition
Char.php:224
PlanetTeamSpeak\TeamSpeak3Framework\Helper\Char\toHex
toHex()
Definition
Char.php:188
PlanetTeamSpeak\TeamSpeak3Framework\Helper\Char\isControl
isControl()
Definition
Char.php:82
PlanetTeamSpeak\TeamSpeak3Framework\Helper\Char\isLower
isLower()
Definition
Char.php:122
PlanetTeamSpeak\TeamSpeak3Framework\Helper\Char\toAscii
toAscii()
Definition
Char.php:154
PlanetTeamSpeak\TeamSpeak3Framework\Helper\Char\toUnicode
toUnicode()
Definition
Char.php:164
PlanetTeamSpeak\TeamSpeak3Framework\Helper\Char\toString
toString()
Definition
Char.php:214
PlanetTeamSpeak\TeamSpeak3Framework\Helper\Char\isDigit
isDigit()
Definition
Char.php:52
PlanetTeamSpeak\TeamSpeak3Framework\Helper\Char\fromHex
static fromHex(string $hex)
Definition
Char.php:200
PlanetTeamSpeak\TeamSpeak3Framework\Helper\Char\isNull
isNull()
Definition
Char.php:102
PlanetTeamSpeak\TeamSpeak3Framework\Helper\Char\$char
string $char
Definition
Char.php:20
PlanetTeamSpeak\TeamSpeak3Framework\Helper\Char\isSpace
isSpace()
Definition
Char.php:62
PlanetTeamSpeak\TeamSpeak3Framework\Helper\Char\toUpper
toUpper()
Definition
Char.php:133
PlanetTeamSpeak\TeamSpeak3Framework\Helper\Char\__toString
__toString()
Definition
Char.php:234
PlanetTeamSpeak\TeamSpeak3Framework\Helper\Char\isLetter
isLetter()
Definition
Char.php:42
PlanetTeamSpeak\TeamSpeak3Framework\Helper\Char\isUpper
isUpper()
Definition
Char.php:112
PlanetTeamSpeak\TeamSpeak3Framework\Helper\Char\toLower
toLower()
Definition
Char.php:144
PlanetTeamSpeak\TeamSpeak3Framework\Helper\Char\isMark
isMark()
Definition
Char.php:72
PlanetTeamSpeak\TeamSpeak3Framework\Helper\Char\__construct
__construct(string $char)
Definition
Char.php:28
PlanetTeamSpeak\TeamSpeak3Framework\Helper
Definition
Char.php:3
src
Helper
Char.php
Generated by
1.14.0