[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

/vendor/s9e/text-formatter/src/Configurator/Helpers/ -> RegexpBuilder.php (source)

   1  <?php
   2  
   3  /**
   4  * @package   s9e\TextFormatter
   5  * @copyright Copyright (c) 2010-2022 The s9e authors
   6  * @license   http://www.opensource.org/licenses/mit-license.php The MIT License
   7  */
   8  namespace s9e\TextFormatter\Configurator\Helpers;
   9  
  10  use s9e\RegexpBuilder\Builder;
  11  
  12  abstract class RegexpBuilder
  13  {
  14      /**
  15      * Create a regexp pattern that matches a list of words
  16      *
  17      * @param  array  $words   Words to sort (must be UTF-8)
  18      * @param  array  $options
  19      * @return string
  20      */
  21  	public static function fromList(array $words, array $options = [])
  22      {
  23          $options += [
  24              'delimiter'       => '/',
  25              'caseInsensitive' => false,
  26              'specialChars'    => [],
  27              'unicode'         => true
  28          ];
  29  
  30          // Normalize ASCII if the regexp is meant to be case-insensitive
  31          if ($options['caseInsensitive'])
  32          {
  33              foreach ($words as &$word)
  34              {
  35                  $word = strtr($word, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz');
  36              }
  37              unset($word);
  38          }
  39  
  40          $builder = new Builder([
  41              'delimiter' => $options['delimiter'],
  42              'meta'      => $options['specialChars'],
  43              'input'     => $options['unicode'] ? 'Utf8' : 'Bytes',
  44              'output'    => $options['unicode'] ? 'Utf8' : 'Bytes'
  45          ]);
  46  
  47          return $builder->build($words);
  48      }
  49  }


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