[ Index ]

PHP Cross Reference of phpBB-3.3.14-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-2022 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  use function chr, sprintf;
  12  
  13  class Utf8 extends BaseImplementation
  14  {
  15      /** {@inheritdoc} */
  16      protected $maxValue = 0x10FFFF;
  17  
  18      /**
  19      * {@inheritdoc}
  20      */
  21  	protected function outputValidValue(int $value): string
  22      {
  23          if ($value < 0x80)
  24          {
  25              return chr($value);
  26          }
  27          if ($value < 0x800)
  28          {
  29              return chr(0xC0 | ($value >> 6)) . chr(0x80 | ($value & 0x3F));
  30          }
  31          if ($value < 0x10000)
  32          {
  33              return chr(0xE0 | ($value >> 12))
  34                   . chr(0x80 | (($value >> 6) & 0x3F))
  35                   . chr(0x80 | ($value & 0x3F));
  36          }
  37          return chr(0xF0 | ($value >> 18))
  38               . chr(0x80 | (($value >> 12) & 0x3F))
  39               . chr(0x80 | (($value >> 6) & 0x3F))
  40               . chr(0x80 | ($value & 0x3F));
  41      }
  42  
  43      /**
  44      * {@inheritdoc}
  45      */
  46  	protected function validate(int $value): void
  47      {
  48          if ($value >= 0xD800 && $value <= 0xDFFF)
  49          {
  50              throw new InvalidArgumentException(sprintf('Surrogate 0x%X is not a valid UTF-8 character', $value));
  51          }
  52  
  53          parent::validate($value);
  54      }
  55  }


Generated: Mon Nov 25 19:05:08 2024 Cross-referenced by PHPXref 0.7.1