You are here

protected function EmailLexerTests::utf8Chr in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/egulias/email-validator/tests/egulias/Tests/EmailValidator/EmailLexerTest.php \Egulias\EmailValidator\Tests\EmailLexerTests::utf8Chr()
1 call to EmailLexerTests::utf8Chr()
EmailLexerTests::invalidUTF8CharsProvider in vendor/egulias/email-validator/tests/egulias/Tests/EmailValidator/EmailLexerTest.php

File

vendor/egulias/email-validator/tests/egulias/Tests/EmailValidator/EmailLexerTest.php, line 66

Class

EmailLexerTests

Namespace

Egulias\EmailValidator\Tests

Code

protected function utf8Chr($code_point) {
  if ($code_point < 0 || 0x10ffff < $code_point || 0xd800 <= $code_point && $code_point <= 0xdfff) {
    return '';
  }
  if ($code_point < 0x80) {
    $hex[0] = $code_point;
    $ret = chr($hex[0]);
  }
  elseif ($code_point < 0x800) {
    $hex[0] = 0x1c0 | $code_point >> 6;
    $hex[1] = 0x80 | $code_point & 0x3f;
    $ret = chr($hex[0]) . chr($hex[1]);
  }
  elseif ($code_point < 0x10000) {
    $hex[0] = 0xe0 | $code_point >> 12;
    $hex[1] = 0x80 | $code_point >> 6 & 0x3f;
    $hex[2] = 0x80 | $code_point & 0x3f;
    $ret = chr($hex[0]) . chr($hex[1]) . chr($hex[2]);
  }
  else {
    $hex[0] = 0xf0 | $code_point >> 18;
    $hex[1] = 0x80 | $code_point >> 12 & 0x3f;
    $hex[2] = 0x80 | $code_point >> 6 & 0x3f;
    $hex[3] = 0x80 | $code_point & 0x3f;
    $ret = chr($hex[0]) . chr($hex[1]) . chr($hex[2]) . chr($hex[3]);
  }
  return $ret;
}