function Xml::isUtf8
1 call to Xml::isUtf8()
- Xml::convertToUtf8 in vendor/
phpunit/ phpunit/ src/ Util/ Xml/ Xml.php
File
-
vendor/
phpunit/ phpunit/ src/ Util/ Xml/ Xml.php, line 55
Class
- Xml
- @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
Namespace
PHPUnit\UtilCode
private static function isUtf8(string $string) : bool {
$length = strlen($string);
for ($i = 0; $i < $length; $i++) {
if (ord($string[$i]) < 0x80) {
$n = 0;
}
elseif ((ord($string[$i]) & 0xe0) === 0xc0) {
$n = 1;
}
elseif ((ord($string[$i]) & 0xf0) === 0xe0) {
$n = 2;
}
elseif ((ord($string[$i]) & 0xf0) === 0xf0) {
$n = 3;
}
else {
return false;
}
for ($j = 0; $j < $n; $j++) {
if (++$i === $length || (ord($string[$i]) & 0xc0) !== 0x80) {
return false;
}
}
}
return true;
}