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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
AbstractScript.php
001 <?php
002
003 /**
004 * @package s9e\TextFormatter
005 * @copyright Copyright (c) 2010-2022 The s9e authors
006 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
007 */
008 namespace s9e\TextFormatter\Plugins\Litedown\Parser\Passes;
009
010 abstract class AbstractScript extends AbstractPass
011 {
012 /**
013 * @var string $longRegexp Regexp used for the long form syntax
014 */
015 protected $longRegexp;
016
017 /**
018 * @var string Regexp used for the short form syntax
019 */
020 protected $shortRegexp;
021
022 /**
023 * @var string Relevant character used by this syntax
024 */
025 protected $syntaxChar;
026
027 /**
028 * @var string Name of the tag used by this pass
029 */
030 protected $tagName;
031
032 /**
033 * @param string $tagName Name of the tag used by this pass
034 * @param string $syntaxChar Relevant character used by this syntax
035 * @param string $shortRegexp Regexp used for the short form syntax
036 * @param string $longRegexp Regexp used for the long form syntax
037 * @return void
038 */
039 protected function parseAbstractScript($tagName, $syntaxChar, $shortRegexp, $longRegexp)
040 {
041 $this->tagName = $tagName;
042 $this->syntaxChar = $syntaxChar;
043 $this->shortRegexp = $shortRegexp;
044 $this->longRegexp = $longRegexp;
045
046 $pos = $this->text->indexOf($this->syntaxChar);
047 if ($pos === false)
048 {
049 return;
050 }
051
052 $this->parseShortForm($pos);
053 $this->parseLongForm($pos);
054 }
055
056 /**
057 * Parse the long form x^(x)
058 *
059 * This syntax is supported by RDiscount
060 *
061 * @param integer $pos Position of the first relevant character
062 * @return void
063 */
064 protected function parseLongForm($pos)
065 {
066 $pos = $this->text->indexOf($this->syntaxChar . '(', $pos);
067 if ($pos === false)
068 {
069 return;
070 }
071
072 preg_match_all($this->longRegexp, $this->text, $matches, PREG_OFFSET_CAPTURE, $pos);
073 foreach ($matches[0] as list($match, $matchPos))
074 {
075 $matchLen = strlen($match);
076
077 $this->parser->addTagPair($this->tagName, $matchPos, 2, $matchPos + $matchLen - 1, 1);
078 $this->text->overwrite($matchPos, $matchLen);
079 }
080 if (!empty($matches[0]))
081 {
082 $this->parseLongForm($pos);
083 }
084 }
085
086 /**
087 * Parse the short form x^x and x^x^
088 *
089 * This syntax is supported by most implementations that support superscript
090 *
091 * @param integer $pos Position of the first relevant character
092 * @return void
093 */
094 protected function parseShortForm($pos)
095 {
096 preg_match_all($this->shortRegexp, $this->text, $matches, PREG_OFFSET_CAPTURE, $pos);
097 foreach ($matches[0] as list($match, $matchPos))
098 {
099 $matchLen = strlen($match);
100 $startPos = $matchPos;
101 $endLen = (substr($match, -1) === $this->syntaxChar) ? 1 : 0;
102 $endPos = $matchPos + $matchLen - $endLen;
103
104 $this->parser->addTagPair($this->tagName, $startPos, 1, $endPos, $endLen);
105 }
106 }
107 }