[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

/vendor/s9e/regexp-builder/src/Passes/ -> GroupSingleCharacters.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\Passes;
   9  
  10  use function array_diff_key, array_filter, array_unshift, array_values, count;
  11  
  12  /**
  13  * Replaces (?:aa|b|cc|d) with (?:[bd]|aa|cc)
  14  * Enables other passes to replace (?:[xy]|a[xy]) with a?[xy]
  15  */
  16  class GroupSingleCharacters extends AbstractPass
  17  {
  18      /**
  19      * {@inheritdoc}
  20      */
  21  	protected function runPass(array $strings): array
  22      {
  23          $singles = $this->getSingleCharStrings($strings);
  24          $cnt     = count($singles);
  25          if ($cnt > 1 && $cnt < count($strings))
  26          {
  27              // Remove the singles from the input, then prepend them as a new string
  28              $strings = array_diff_key($strings, $singles);
  29              array_unshift($strings, [array_values($singles)]);
  30          }
  31  
  32          return $strings;
  33      }
  34  
  35      /**
  36      * Return an array of every single-char string in given list of strings
  37      *
  38      * @param  array[] $strings
  39      * @return array[]
  40      */
  41  	protected function getSingleCharStrings(array $strings): array
  42      {
  43          return array_filter($strings, [$this, 'isSingleCharString']);
  44      }
  45  }


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