Completed
Push — master ( 06252b...52b075 )
by Tom
03:06
created

BracketMatcher::getClosePos()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/* @description     Transformation Style Sheets - Revolutionising PHP templating    *
3
 * @author          Tom Butler [email protected]                                             *
4
 * @copyright       2015 Tom Butler <[email protected]> | https://r.je/                      *
5
 * @license         http://www.opensource.org/licenses/bsd-license.php  BSD License *
6
 * @version         1.0                                                             */
7
namespace Transphporm\Parser;
8
class BracketMatcher {
9
	private $str;
10
	private $startPos = 0;
11
	private $endPos = 0;
12
13
	public function __construct($str) {
14
		$this->str = $str;
15
	}
16
	
17
	public function match($openChr, $closingChr, $start = 0) {
18
		$open = strpos($this->str, $openChr, $start);
19
		$close = strpos($this->str, $closingChr, $open);
20
21
		$cPos = $open+1;
22
		while (($cPos = strpos($this->str, $openChr, $cPos+1)) !== false && $cPos < $close) $close = strpos($this->str, $closingChr, $close+1);
23
24
		$this->startPos = $open;
25
		$this->endPos = $close;
26
		return substr($this->str, $open+1, $close-$open-1);
27
	}
28
29
	public function getOpenPos() {
30
		return $this->startPos;
31
	}
32
33
	public function getClosePos() {
34
		return $this->endPos;
35
	}
36
}