Completed
Push — master ( f5a4f7...862e70 )
by Richard
02:25
created

SheetTokenizer::getTokens()   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
namespace Transphporm\Parser;
3
class SheetTokenizer {
4
    private $tokenizer;
5
6
    public function __construct($tss) {
7
        $tss = $this->stripComments($tss, '//', "\n");
8
		$tss = $this->stripComments($tss, '/*', '*/');
9
		$this->tokenizer = new Tokenizer($tss);
10
    }
11
12
    public function getTokens() {
13
		return $this->tokenizer->getTokens();
14
    }
15
16
    private function stripComments($str, $open, $close) {
17
		$pos = 0;
18
		while (($pos = strpos($str, $open, $pos)) !== false) {
19
			$end = strpos($str, $close, $pos);
20
			if ($end === false) break;
21
			$str = substr_replace($str, '', $pos, $end-$pos+strlen($close));
22
		}
23
24
		return $str;
25
	}
26
}
27