[ Index ] |
PHP Cross Reference of phpBB-3.3.14-deutsch |
[Summary view] [Print] [Text view]
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\Plugins\Litedown\Parser\Passes; 9 10 abstract class AbstractScript extends AbstractPass 11 { 12 /** 13 * @var string $longRegexp Regexp used for the long form syntax 14 */ 15 protected $longRegexp; 16 17 /** 18 * @var string Regexp used for the short form syntax 19 */ 20 protected $shortRegexp; 21 22 /** 23 * @var string Relevant character used by this syntax 24 */ 25 protected $syntaxChar; 26 27 /** 28 * @var string Name of the tag used by this pass 29 */ 30 protected $tagName; 31 32 /** 33 * @param string $tagName Name of the tag used by this pass 34 * @param string $syntaxChar Relevant character used by this syntax 35 * @param string $shortRegexp Regexp used for the short form syntax 36 * @param string $longRegexp Regexp used for the long form syntax 37 * @return void 38 */ 39 protected function parseAbstractScript($tagName, $syntaxChar, $shortRegexp, $longRegexp) 40 { 41 $this->tagName = $tagName; 42 $this->syntaxChar = $syntaxChar; 43 $this->shortRegexp = $shortRegexp; 44 $this->longRegexp = $longRegexp; 45 46 $pos = $this->text->indexOf($this->syntaxChar); 47 if ($pos === false) 48 { 49 return; 50 } 51 52 $this->parseShortForm($pos); 53 $this->parseLongForm($pos); 54 } 55 56 /** 57 * Parse the long form x^(x) 58 * 59 * This syntax is supported by RDiscount 60 * 61 * @param integer $pos Position of the first relevant character 62 * @return void 63 */ 64 protected function parseLongForm($pos) 65 { 66 $pos = $this->text->indexOf($this->syntaxChar . '(', $pos); 67 if ($pos === false) 68 { 69 return; 70 } 71 72 preg_match_all($this->longRegexp, $this->text, $matches, PREG_OFFSET_CAPTURE, $pos); 73 foreach ($matches[0] as list($match, $matchPos)) 74 { 75 $matchLen = strlen($match); 76 77 $this->parser->addTagPair($this->tagName, $matchPos, 2, $matchPos + $matchLen - 1, 1); 78 $this->text->overwrite($matchPos, $matchLen); 79 } 80 if (!empty($matches[0])) 81 { 82 $this->parseLongForm($pos); 83 } 84 } 85 86 /** 87 * Parse the short form x^x and x^x^ 88 * 89 * This syntax is supported by most implementations that support superscript 90 * 91 * @param integer $pos Position of the first relevant character 92 * @return void 93 */ 94 protected function parseShortForm($pos) 95 { 96 preg_match_all($this->shortRegexp, $this->text, $matches, PREG_OFFSET_CAPTURE, $pos); 97 foreach ($matches[0] as list($match, $matchPos)) 98 { 99 $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 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Nov 25 19:05:08 2024 | Cross-referenced by PHPXref 0.7.1 |