Group.php
2.27 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
<?php
namespace SearchWP\Dependencies\RtfHtmlPhp;
class Group extends Element
{
public $parent;
public $children;
/*
* Create a new Group, with no parent and no children.
*/
public function __construct()
{
$this->parent = null;
$this->children = array();
}
public function GetType()
{
// No children? Then the group type is null.
if (\sizeof($this->children) == 0) {
return null;
}
// If the first child is a control word, then
// the group type is the word.
$child = $this->children[0];
if ($child instanceof ControlWord) {
return $child->word;
} elseif ($child instanceof ControlSymbol) {
return $child->symbol == '*' ? '*' : null;
}
// If first child is neither word nor symbol, then
// group type is null.
return null;
}
// If a group contains a * symbol as its first child,
// then it is a destination group.
public function IsDestination()
{
// If group has no children, then destination is null.
if (\sizeof($this->children) == 0) {
return null;
}
// First child not a control symbol?
$child = $this->children[0];
if (!$child instanceof ControlSymbol) {
return null;
}
return $child->symbol == '*';
}
//
// Convert Group to string for debugging purposes.
//
public function toString(int $level = 0)
{
$str = \str_repeat(" ", $level) . "{\n";
foreach ($this->children as $child) {
/*
// Skip some group types:
if($child instanceof Group) {
if ($child->GetType() == "fonttbl") continue;
if ($child->GetType() == "colortbl") continue;
if ($child->GetType() == "stylesheet") continue;
if ($child->GetType() == "info") continue;
// Skip any pictures:
if (substr($child->GetType(), 0, 4) == "pict") continue;
if ($child->IsDestination()) continue;
} */
$str .= $child->toString($level + 1);
}
return $str . \str_repeat(" ", $level) . "}\n";
}
}