Completed
Branch wip/litedown (e234a3)
by Josh
31:46 queued 18:30
created

Superscript   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 37
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B parse() 0 31 4
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\Passes;
9
10
class Superscript extends AbstractPass
11
{
12
	/**
13
	* {@inheritdoc}
14
	*/
15 263
	public function parse()
16
	{
17 263
		$pos = $this->text->indexOf('^');
18 263
		if ($pos === false)
19 263
		{
20 261
			return;
21
		}
22
23 2
		preg_match_all(
24 2
			'/\\^[^\\x17\\s]++/',
25 2
			$this->text,
26 2
			$matches,
27 2
			PREG_OFFSET_CAPTURE,
28
			$pos
29 2
		);
30 2
		foreach ($matches[0] as list($match, $matchPos))
31
		{
32 1
			$matchLen = strlen($match);
33 1
			$startPos = $matchPos;
34 1
			$endPos   = $matchPos + $matchLen;
35
36 1
			$parts = explode('^', $match);
37 1
			unset($parts[0]);
38
39 1
			foreach ($parts as $part)
40
			{
41 1
				$this->parser->addTagPair('SUP', $startPos, 1, $endPos, 0);
42 1
				$startPos += 1 + strlen($part);
43 1
			}
44 2
		}
45
	}
46
}