Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

Glob.php

Zuletzt modifiziert: 09.10.2024, 12:54 - Dateigröße: 3.21 KiB


001  <?php
002   
003  /*
004   * This file is part of the Symfony package.
005   *
006   * (c) Fabien Potencier <fabien@symfony.com>
007   *
008   * For the full copyright and license information, please view the LICENSE
009   * file that was distributed with this source code.
010   */
011   
012  namespace Symfony\Component\Finder;
013   
014  /**
015   * Glob matches globbing patterns against text.
016   *
017   *   if match_glob("foo.*", "foo.bar") echo "matched\n";
018   *
019   * // prints foo.bar and foo.baz
020   * $regex = glob_to_regex("foo.*");
021   * for (array('foo.bar', 'foo.baz', 'foo', 'bar') as $t)
022   * {
023   *   if (/$regex/) echo "matched: $car\n";
024   * }
025   *
026   * Glob implements glob(3) style matching that can be used to match
027   * against text, rather than fetching names from a filesystem.
028   *
029   * Based on the Perl Text::Glob module.
030   *
031   * @author Fabien Potencier <fabien@symfony.com> PHP port
032   * @author     Richard Clamp <richardc@unixbeard.net> Perl version
033   * @copyright  2004-2005 Fabien Potencier <fabien@symfony.com>
034   * @copyright  2002 Richard Clamp <richardc@unixbeard.net>
035   */
036  class Glob
037  {
038      /**
039       * Returns a regexp which is the equivalent of the glob pattern.
040       *
041       * @param string $glob                The glob pattern
042       * @param bool   $strictLeadingDot
043       * @param bool   $strictWildcardSlash
044       * @param string $delimiter           Optional delimiter
045       *
046       * @return string regex The regexp
047       */
048      public static function toRegex($glob, $strictLeadingDot = true, $strictWildcardSlash = true, $delimiter = '#')
049      {
050          $firstByte = true;
051          $escaping = false;
052          $inCurlies = 0;
053          $regex = '';
054          $sizeGlob = strlen($glob);
055          for ($i = 0; $i < $sizeGlob; ++$i) {
056              $car = $glob[$i];
057              if ($firstByte) {
058                  if ($strictLeadingDot && '.' !== $car) {
059                      $regex .= '(?=[^\.])';
060                  }
061   
062                  $firstByte = false;
063              }
064   
065              if ('/' === $car) {
066                  $firstByte = true;
067              }
068   
069              if ($delimiter === $car || '.' === $car || '(' === $car || ')' === $car || '|' === $car || '+' === $car || '^' === $car || '$' === $car) {
070                  $regex .= "\\$car";
071              } elseif ('*' === $car) {
072                  $regex .= $escaping ? '\\*' : ($strictWildcardSlash ? '[^/]*' : '.*');
073              } elseif ('?' === $car) {
074                  $regex .= $escaping ? '\\?' : ($strictWildcardSlash ? '[^/]' : '.');
075              } elseif ('{' === $car) {
076                  $regex .= $escaping ? '\\{' : '(';
077                  if (!$escaping) {
078                      ++$inCurlies;
079                  }
080              } elseif ('}' === $car && $inCurlies) {
081                  $regex .= $escaping ? '}' : ')';
082                  if (!$escaping) {
083                      --$inCurlies;
084                  }
085              } elseif (',' === $car && $inCurlies) {
086                  $regex .= $escaping ? ',' : '|';
087              } elseif ('\\' === $car) {
088                  if ($escaping) {
089                      $regex .= '\\\\';
090                      $escaping = false;
091                  } else {
092                      $escaping = true;
093                  }
094   
095                  continue;
096              } else {
097                  $regex .= $car;
098              }
099              $escaping = false;
100          }
101   
102          return $delimiter.'^'.$regex.'$'.$delimiter;
103      }
104  }
105