[ Index ]

PHP Cross Reference of phpBB-3.3.11-deutsch

title

Body

[close]

/vendor/s9e/regexp-builder/src/Passes/ -> PromoteSingleStrings.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_map, array_merge, count, is_array;
  11  
  12  /**
  13  * Replaces alternations that only contain one string to allow other passes to replace
  14  * (?:a0?x|bx) with (?:a0?|b)x
  15  */
  16  class PromoteSingleStrings extends AbstractPass
  17  {
  18      /**
  19      * {@inheritdoc}
  20      */
  21  	protected function runPass(array $strings): array
  22      {
  23          return array_map([$this, 'promoteSingleStrings'], $strings);
  24      }
  25  
  26      /**
  27      * Promote single strings found inside given string
  28      *
  29      * @param  array $string Original string
  30      * @return array         Modified string
  31      */
  32  	protected function promoteSingleStrings(array $string): array
  33      {
  34          $newString = [];
  35          foreach ($string as $element)
  36          {
  37              if (is_array($element) && count($element) === 1)
  38              {
  39                  $newString = array_merge($newString, $element[0]);
  40              }
  41              else
  42              {
  43                  $newString[] = $element;
  44              }
  45          }
  46  
  47          return $newString;
  48      }
  49  }


Generated: Sat Nov 4 14:26:03 2023 Cross-referenced by PHPXref 0.7.1