[ Index ]

PHP Cross Reference of phpBB-3.3.7-deutsch

title

Body

[close]

/vendor/s9e/regexp-builder/src/Output/ -> Utf8.php (source)

   1  <?php declare(strict_types=1);
   2  
   3  /**
   4  * @package   s9e\RegexpBuilder
   5  * @copyright Copyright (c) 2016-2021 The s9e authors
   6  * @license   http://www.opensource.org/licenses/mit-license.php The MIT License
   7  */
   8  namespace s9e\RegexpBuilder\Output;
   9  
  10  use InvalidArgumentException;
  11  
  12  class Utf8 extends BaseImplementation
  13  {
  14      /** {@inheritdoc} */
  15      protected $maxValue = 0x10FFFF;
  16  
  17      /**
  18      * {@inheritdoc}
  19      */
  20  	protected function outputValidValue(int $value): string
  21      {
  22          if ($value < 0x80)
  23          {
  24              return chr($value);
  25          }
  26          if ($value < 0x800)
  27          {
  28              return chr(0xC0 | ($value >> 6)) . chr(0x80 | ($value & 0x3F));
  29          }
  30          if ($value < 0x10000)
  31          {
  32              return chr(0xE0 | ($value >> 12))
  33                   . chr(0x80 | (($value >> 6) & 0x3F))
  34                   . chr(0x80 | ($value & 0x3F));
  35          }
  36          return chr(0xF0 | ($value >> 18))
  37               . chr(0x80 | (($value >> 12) & 0x3F))
  38               . chr(0x80 | (($value >> 6) & 0x3F))
  39               . chr(0x80 | ($value & 0x3F));
  40      }
  41  
  42      /**
  43      * {@inheritdoc}
  44      */
  45  	protected function validate(int $value): void
  46      {
  47          if ($value >= 0xD800 && $value <= 0xDFFF)
  48          {
  49              throw new InvalidArgumentException(sprintf('Surrogate 0x%X is not a valid UTF-8 character', $value));
  50          }
  51  
  52          parent::validate($value);
  53      }
  54  }


Generated: Thu Mar 24 21:31:15 2022 Cross-referenced by PHPXref 0.7.1