Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

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

Unescaper.php

Zuletzt modifiziert: 02.04.2025, 15:02 - Dateigröße: 3.84 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\Yaml;
013   
014  use Symfony\Component\Yaml\Exception\ParseException;
015   
016  /**
017   * Unescaper encapsulates unescaping rules for single and double-quoted
018   * YAML strings.
019   *
020   * @author Matthew Lewinski <matthew@lewinski.org>
021   *
022   * @internal
023   */
024  class Unescaper
025  {
026      /**
027       * Regex fragment that matches an escaped character in a double quoted string.
028       */
029      const REGEX_ESCAPED_CHARACTER = '\\\\(x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8}|.)';
030   
031      /**
032       * Unescapes a single quoted string.
033       *
034       * @param string $value A single quoted string
035       *
036       * @return string The unescaped string
037       */
038      public function unescapeSingleQuotedString($value)
039      {
040          return str_replace('\'\'', '\'', $value);
041      }
042   
043      /**
044       * Unescapes a double quoted string.
045       *
046       * @param string $value A double quoted string
047       *
048       * @return string The unescaped string
049       */
050      public function unescapeDoubleQuotedString($value)
051      {
052          $callback = function ($match) {
053              return $this->unescapeCharacter($match[0]);
054          };
055   
056          // evaluate the string
057          return preg_replace_callback('/'.self::REGEX_ESCAPED_CHARACTER.'/u', $callback, $value);
058      }
059   
060      /**
061       * Unescapes a character that was found in a double-quoted string.
062       *
063       * @param string $value An escaped character
064       *
065       * @return string The unescaped character
066       */
067      private function unescapeCharacter($value)
068      {
069          switch ($value[1]) {
070              case '0':
071                  return "\x0";
072              case 'a':
073                  return "\x7";
074              case 'b':
075                  return "\x8";
076              case 't':
077                  return "\t";
078              case "\t":
079                  return "\t";
080              case 'n':
081                  return "\n";
082              case 'v':
083                  return "\xB";
084              case 'f':
085                  return "\xC";
086              case 'r':
087                  return "\r";
088              case 'e':
089                  return "\x1B";
090              case ' ':
091                  return ' ';
092              case '"':
093                  return '"';
094              case '/':
095                  return '/';
096              case '\\':
097                  return '\\';
098              case 'N':
099                  // U+0085 NEXT LINE
100                  return "\xC2\x85";
101              case '_':
102                  // U+00A0 NO-BREAK SPACE
103                  return "\xC2\xA0";
104              case 'L':
105                  // U+2028 LINE SEPARATOR
106                  return "\xE2\x80\xA8";
107              case 'P':
108                  // U+2029 PARAGRAPH SEPARATOR
109                  return "\xE2\x80\xA9";
110              case 'x':
111                  return self::utf8chr(hexdec(substr($value, 2, 2)));
112              case 'u':
113                  return self::utf8chr(hexdec(substr($value, 2, 4)));
114              case 'U':
115                  return self::utf8chr(hexdec(substr($value, 2, 8)));
116              default:
117                  throw new ParseException(sprintf('Found unknown escape character "%s".', $value));
118          }
119      }
120   
121      /**
122       * Get the UTF-8 character for the given code point.
123       *
124       * @param int $c The unicode code point
125       *
126       * @return string The corresponding UTF-8 character
127       */
128      private static function utf8chr($c)
129      {
130          if (0x80 > $c %= 0x200000) {
131              return \chr($c);
132          }
133          if (0x800 > $c) {
134              return \chr(0xC0 | $c >> 6).\chr(0x80 | $c & 0x3F);
135          }
136          if (0x10000 > $c) {
137              return \chr(0xE0 | $c >> 12).\chr(0x80 | $c >> 6 & 0x3F).\chr(0x80 | $c & 0x3F);
138          }
139   
140          return \chr(0xF0 | $c >> 18).\chr(0x80 | $c >> 12 & 0x3F).\chr(0x80 | $c >> 6 & 0x3F).\chr(0x80 | $c & 0x3F);
141      }
142  }
143