You are here

protected static function PHPUnit_Util_String::isUtf8 in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/phpunit/phpunit/src/Util/String.php \PHPUnit_Util_String::isUtf8()

Checks a string for UTF-8 encoding.

Parameters

string $string:

Return value

bool

1 call to PHPUnit_Util_String::isUtf8()
PHPUnit_Util_String::convertToUtf8 in vendor/phpunit/phpunit/src/Util/String.php
Converts a string to UTF-8 encoding.

File

vendor/phpunit/phpunit/src/Util/String.php, line 43

Class

PHPUnit_Util_String
String helpers.

Code

protected static function isUtf8($string) {
  $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;
}