-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRange.php
More file actions
92 lines (72 loc) · 2.21 KB
/
Copy pathRange.php
File metadata and controls
92 lines (72 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
namespace TaskChecker\TextScanner;
class Range
{
private $text;
private $startBefore;
private $endBefore;
private function __construct(TokenArray $text, $startBefore, $endBefore)
{
$this->text = $text;
$this->startBefore = $startBefore;
$this->endBefore = $endBefore;
}
public static function createEmpty(TokenArray $text, $before = 0)
{
return new self($text, $before, $before);
}
public static function createIncluding(TokenArray $text, $from, $to)
{
return new self($text, $from, $to + 1);
}
public static function createExcludingEnd(TokenArray $text, $startBefore, $endBefore)
{
return new self($text, $startBefore, $endBefore);
}
public function getString()
{
$string = '';
for ($i = $this->startBefore; $i < $this->endBefore; $i++) {
$string .= $this->text->getTokenStringAt($i);
}
return $string;
}
public function getLength()
{
return $this->endBefore - $this->startBefore;
}
public function getTokenStringAt($pos)
{
assert($pos < $this->getLength());
return $this->text->getTokenStringAt($pos + $this->startBefore);
}
public function getStartBefore()
{
return $this->startBefore;
}
public function getEndBefore()
{
return $this->endBefore;
}
public function doesIntersect(Range $other)
{
return $other->endBefore > $this->startBefore &&
$other->startBefore < $this->endBefore;
}
public function getDescription()
{
return "[{$this->startBefore}..{$this->endBefore})";
}
public function getLineAndColumn()
{
assert($this->getLength() > 0);
$start = $this->text->getLineAndColumnAt($this->startBefore);
$end = $this->text->getLineAndColumnAt($this->endBefore - 1);
return array(
'line' => $start['line'],
'col' => $start['col'],
'endLine' => $end['endLine'],
'endCol' => $end['endCol']
);
}
}