[ Index ] |
PHP Cross Reference of phpBB-3.2.11-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 * @package s9e\TextFormatter 5 * @copyright Copyright (c) 2010-2019 The s9e Authors 6 * @license http://www.opensource.org/licenses/mit-license.php The MIT License 7 */ 8 namespace s9e\TextFormatter\Plugins\FancyPants; 9 use s9e\TextFormatter\Plugins\ParserBase; 10 class Parser extends ParserBase 11 { 12 protected $hasDoubleQuote; 13 protected $hasSingleQuote; 14 protected $text; 15 public function parse($text, array $matches) 16 { 17 $this->text = $text; 18 $this->hasSingleQuote = (\strpos($text, "'") !== \false); 19 $this->hasDoubleQuote = (\strpos($text, '"') !== \false); 20 if (empty($this->config['disableQuotes'])) 21 { 22 $this->parseSingleQuotes(); 23 $this->parseSingleQuotePairs(); 24 $this->parseDoubleQuotePairs(); 25 } 26 if (empty($this->config['disableGuillemets'])) 27 $this->parseGuillemets(); 28 if (empty($this->config['disableMathSymbols'])) 29 { 30 $this->parseNotEqualSign(); 31 $this->parseSymbolsAfterDigits(); 32 $this->parseFractions(); 33 } 34 if (empty($this->config['disablePunctuation'])) 35 $this->parseDashesAndEllipses(); 36 if (empty($this->config['disableSymbols'])) 37 $this->parseSymbolsInParentheses(); 38 unset($this->text); 39 } 40 protected function addTag($tagPos, $tagLen, $chr, $prio = 0) 41 { 42 $tag = $this->parser->addSelfClosingTag($this->config['tagName'], $tagPos, $tagLen, $prio); 43 $tag->setAttribute($this->config['attrName'], $chr); 44 return $tag; 45 } 46 protected function parseDashesAndEllipses() 47 { 48 if (\strpos($this->text, '...') === \false && \strpos($this->text, '--') === \false) 49 return; 50 $chrs = [ 51 '--' => "\xE2\x80\x93", 52 '---' => "\xE2\x80\x94", 53 '...' => "\xE2\x80\xA6" 54 ]; 55 $regexp = '/---?|\\.\\.\\./S'; 56 \preg_match_all($regexp, $this->text, $matches, \PREG_OFFSET_CAPTURE); 57 foreach ($matches[0] as $m) 58 $this->addTag($m[1], \strlen($m[0]), $chrs[$m[0]]); 59 } 60 protected function parseDoubleQuotePairs() 61 { 62 if ($this->hasDoubleQuote) 63 $this->parseQuotePairs( 64 '/(?<![0-9\\pL])"[^"\\n]+"(?![0-9\\pL])/uS', 65 "\xE2\x80\x9C", 66 "\xE2\x80\x9D" 67 ); 68 } 69 protected function parseFractions() 70 { 71 if (\strpos($this->text, '/') === \false) 72 return; 73 $map = [ 74 '1/4' => "\xC2\xBC", 75 '1/2' => "\xC2\xBD", 76 '3/4' => "\xC2\xBE", 77 '1/7' => "\xE2\x85\x90", 78 '1/9' => "\xE2\x85\x91", 79 '1/10' => "\xE2\x85\x92", 80 '1/3' => "\xE2\x85\x93", 81 '2/3' => "\xE2\x85\x94", 82 '1/5' => "\xE2\x85\x95", 83 '2/5' => "\xE2\x85\x96", 84 '3/5' => "\xE2\x85\x97", 85 '4/5' => "\xE2\x85\x98", 86 '1/6' => "\xE2\x85\x99", 87 '5/6' => "\xE2\x85\x9A", 88 '1/8' => "\xE2\x85\x9B", 89 '3/8' => "\xE2\x85\x9C", 90 '5/8' => "\xE2\x85\x9D", 91 '7/8' => "\xE2\x85\x9E", 92 '0/3' => "\xE2\x86\x89" 93 ]; 94 $regexp = '/\\b(?:0\\/3|1\\/(?:[2-9]|10)|2\\/[35]|3\\/[458]|4\\/5|5\\/[68]|7\\/8)\\b/S'; 95 \preg_match_all($regexp, $this->text, $matches, \PREG_OFFSET_CAPTURE); 96 foreach ($matches[0] as $m) 97 $this->addTag($m[1], \strlen($m[0]), $map[$m[0]]); 98 } 99 protected function parseGuillemets() 100 { 101 if (\strpos($this->text, '<<') === \false) 102 return; 103 $regexp = '/<<( ?)(?! )[^\\n<>]*?[^\\n <>]\\1>>(?!>)/'; 104 \preg_match_all($regexp, $this->text, $matches, \PREG_OFFSET_CAPTURE); 105 foreach ($matches[0] as $m) 106 { 107 $left = $this->addTag($m[1], 2, "\xC2\xAB"); 108 $right = $this->addTag($m[1] + \strlen($m[0]) - 2, 2, "\xC2\xBB"); 109 $left->cascadeInvalidationTo($right); 110 } 111 } 112 protected function parseNotEqualSign() 113 { 114 if (\strpos($this->text, '!=') === \false && \strpos($this->text, '=/=') === \false) 115 return; 116 $regexp = '/\\b (?:!|=\\/)=(?= \\b)/'; 117 \preg_match_all($regexp, $this->text, $matches, \PREG_OFFSET_CAPTURE); 118 foreach ($matches[0] as $m) 119 $this->addTag($m[1] + 1, \strlen($m[0]) - 1, "\xE2\x89\xA0"); 120 } 121 protected function parseQuotePairs($regexp, $leftQuote, $rightQuote) 122 { 123 \preg_match_all($regexp, $this->text, $matches, \PREG_OFFSET_CAPTURE); 124 foreach ($matches[0] as $m) 125 { 126 $left = $this->addTag($m[1], 1, $leftQuote); 127 $right = $this->addTag($m[1] + \strlen($m[0]) - 1, 1, $rightQuote); 128 $left->cascadeInvalidationTo($right); 129 } 130 } 131 protected function parseSingleQuotePairs() 132 { 133 if ($this->hasSingleQuote) 134 $this->parseQuotePairs( 135 "/(?<![0-9\\pL])'[^'\\n]+'(?![0-9\\pL])/uS", 136 "\xE2\x80\x98", 137 "\xE2\x80\x99" 138 ); 139 } 140 protected function parseSingleQuotes() 141 { 142 if (!$this->hasSingleQuote) 143 return; 144 $regexp = "/(?<=\\pL)'|(?<!\\S)'(?=\\pL|[0-9]{2})/uS"; 145 \preg_match_all($regexp, $this->text, $matches, \PREG_OFFSET_CAPTURE); 146 foreach ($matches[0] as $m) 147 $this->addTag($m[1], 1, "\xE2\x80\x99", 10); 148 } 149 protected function parseSymbolsAfterDigits() 150 { 151 if (!$this->hasSingleQuote && !$this->hasDoubleQuote && \strpos($this->text, 'x') === \false) 152 return; 153 $map = [ 154 "'s" => "\xE2\x80\x99", 155 "'" => "\xE2\x80\xB2", 156 "' " => "\xE2\x80\xB2", 157 "'x" => "\xE2\x80\xB2", 158 '"' => "\xE2\x80\xB3", 159 '" ' => "\xE2\x80\xB3", 160 '"x' => "\xE2\x80\xB3" 161 ]; 162 $regexp = "/[0-9](?>'s|[\"']? ?x(?= ?[0-9])|[\"'])/S"; 163 \preg_match_all($regexp, $this->text, $matches, \PREG_OFFSET_CAPTURE); 164 foreach ($matches[0] as $m) 165 { 166 if (\substr($m[0], -1) === 'x') 167 $this->addTag($m[1] + \strlen($m[0]) - 1, 1, "\xC3\x97"); 168 $str = \substr($m[0], 1, 2); 169 if (isset($map[$str])) 170 $this->addTag($m[1] + 1, 1, $map[$str]); 171 } 172 } 173 protected function parseSymbolsInParentheses() 174 { 175 if (\strpos($this->text, '(') === \false) 176 return; 177 $chrs = [ 178 '(c)' => "\xC2\xA9", 179 '(r)' => "\xC2\xAE", 180 '(tm)' => "\xE2\x84\xA2" 181 ]; 182 $regexp = '/\\((?>c|r|tm)\\)/i'; 183 \preg_match_all($regexp, $this->text, $matches, \PREG_OFFSET_CAPTURE); 184 foreach ($matches[0] as $m) 185 $this->addTag($m[1], \strlen($m[0]), $chrs[\strtr($m[0], 'CMRT', 'cmrt')]); 186 } 187 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |