Completed
Branch wip/litedown (377511)
by Josh
03:42
created

Superscript::execute()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 31
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 31
ccs 0
cts 23
cp 0
rs 8.5806
c 0
b 0
f 0
cc 4
eloc 19
nc 4
nop 0
crap 20
1
<?php
2
3
/**
4
* @package   s9e\TextFormatter
5
* @copyright Copyright (c) 2010-2017 The s9e Authors
6
* @license   http://www.opensource.org/licenses/mit-license.php The MIT License
7
*/
8
namespace s9e\TextFormatter\Plugins\Litedown\Parser;
9
10
class Superscript extends AbstractParser
11
{
12
	/**
13
	* {@inheritdoc}
14
	*/
15
	protected function execute()
16
	{
17
		$pos = strpos($this->text, '^');
18
		if ($pos === false)
19
		{
20
			return;
21
		}
22
23
		preg_match_all(
24
			'/\\^[^\\x17\\s]++/',
25
			$this->text,
26
			$matches,
27
			PREG_OFFSET_CAPTURE,
28
			$pos
29
		);
30
		foreach ($matches[0] as list($match, $matchPos))
31
		{
32
			$matchLen    = strlen($match);
33
			$startTagPos = $matchPos;
34
			$endTagPos   = $matchPos + $matchLen;
35
36
			$parts = explode('^', $match);
37
			unset($parts[0]);
38
39
			foreach ($parts as $part)
40
			{
41
				$this->parser->addTagPair('SUP', $startTagPos, 1, $endTagPos, 0);
42
				$startTagPos += 1 + strlen($part);
43
			}
44
		}
45
	}
46
}