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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
Escaper.php
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 /**
015 * Escaper encapsulates escaping rules for single and double-quoted
016 * YAML strings.
017 *
018 * @author Matthew Lewinski <matthew@lewinski.org>
019 *
020 * @internal
021 */
022 class Escaper
023 {
024 // Characters that would cause a dumped string to require double quoting.
025 const REGEX_CHARACTER_TO_ESCAPE = "[\\x00-\\x1f]|\xc2\x85|\xc2\xa0|\xe2\x80\xa8|\xe2\x80\xa9";
026
027 // Mapping arrays for escaping a double quoted string. The backslash is
028 // first to ensure proper escaping because str_replace operates iteratively
029 // on the input arrays. This ordering of the characters avoids the use of strtr,
030 // which performs more slowly.
031 private static $escapees = array('\\', '\\\\', '\\"', '"',
032 "\x00", "\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07",
033 "\x08", "\x09", "\x0a", "\x0b", "\x0c", "\x0d", "\x0e", "\x0f",
034 "\x10", "\x11", "\x12", "\x13", "\x14", "\x15", "\x16", "\x17",
035 "\x18", "\x19", "\x1a", "\x1b", "\x1c", "\x1d", "\x1e", "\x1f",
036 "\xc2\x85", "\xc2\xa0", "\xe2\x80\xa8", "\xe2\x80\xa9");
037 private static $escaped = array('\\\\', '\\"', '\\\\', '\\"',
038 '\\0', '\\x01', '\\x02', '\\x03', '\\x04', '\\x05', '\\x06', '\\a',
039 '\\b', '\\t', '\\n', '\\v', '\\f', '\\r', '\\x0e', '\\x0f',
040 '\\x10', '\\x11', '\\x12', '\\x13', '\\x14', '\\x15', '\\x16', '\\x17',
041 '\\x18', '\\x19', '\\x1a', '\\e', '\\x1c', '\\x1d', '\\x1e', '\\x1f',
042 '\\N', '\\_', '\\L', '\\P');
043
044 /**
045 * Determines if a PHP value would require double quoting in YAML.
046 *
047 * @param string $value A PHP value
048 *
049 * @return bool True if the value would require double quotes
050 */
051 public static function requiresDoubleQuoting($value)
052 {
053 return preg_match('/'.self::REGEX_CHARACTER_TO_ESCAPE.'/u', $value);
054 }
055
056 /**
057 * Escapes and surrounds a PHP value with double quotes.
058 *
059 * @param string $value A PHP value
060 *
061 * @return string The quoted, escaped string
062 */
063 public static function escapeWithDoubleQuotes($value)
064 {
065 return sprintf('"%s"', str_replace(self::$escapees, self::$escaped, $value));
066 }
067
068 /**
069 * Determines if a PHP value would require single quoting in YAML.
070 *
071 * @param string $value A PHP value
072 *
073 * @return bool True if the value would require single quotes
074 */
075 public static function requiresSingleQuoting($value)
076 {
077 // Determines if a PHP value is entirely composed of a value that would
078 // require single quoting in YAML.
079 if (in_array(strtolower($value), array('null', '~', 'true', 'false', 'y', 'n', 'yes', 'no', 'on', 'off'))) {
080 return true;
081 }
082
083 // Determines if the PHP value contains any single characters that would
084 // cause it to require single quoting in YAML.
085 return preg_match('/[ \s \' " \: \{ \} \[ \] , & \* \# \?] | \A[ \- ? | < > = ! % @ ` ]/x', $value);
086 }
087
088 /**
089 * Escapes and surrounds a PHP value with single quotes.
090 *
091 * @param string $value A PHP value
092 *
093 * @return string The quoted, escaped string
094 */
095 public static function escapeWithSingleQuotes($value)
096 {
097 return sprintf("'%s'", str_replace('\'', '\'\'', $value));
098 }
099 }
100