1 | <?php declare(strict_types=1); |
||
15 | class Structure extends AbstractIterable |
||
16 | { |
||
17 | /** string Internal collection name */ |
||
18 | protected const COLLECTION_NAME = 'groups'; |
||
19 | |||
20 | /** array Supported character group types */ |
||
21 | const CG_TYPES = [ |
||
22 | FixedVariableCG::class, |
||
23 | VariableFixedCG::class, |
||
24 | VariableCG::class, |
||
25 | FixedCG::class, |
||
26 | ]; |
||
27 | |||
28 | /** @var AbstractCG[] */ |
||
29 | public $groups = []; |
||
30 | |||
31 | /** @var string Input string */ |
||
32 | public $string; |
||
33 | |||
34 | /** |
||
35 | * Create string character group structure from string string. |
||
36 | * |
||
37 | * @param string $input Input string for string character group structure |
||
38 | */ |
||
39 | 21 | public function __construct(string $input) |
|
57 | |||
58 | /** |
||
59 | * Compare structure character groups. |
||
60 | * |
||
61 | * @param Structure $structure Compared string structure group |
||
62 | * |
||
63 | * @return int Comparison result |
||
64 | */ |
||
65 | 18 | public function compare(Structure $structure): int |
|
86 | |||
87 | /** |
||
88 | * Get longest common prefix between strings. |
||
89 | * |
||
90 | * @param Structure $compared Compared character group structure |
||
91 | * |
||
92 | * @return string Strings Longest common prefix or empty string |
||
93 | * |
||
94 | */ |
||
95 | 3 | public function getCommonPrefix(Structure $compared) |
|
121 | |||
122 | /** |
||
123 | * Define shortest structure. |
||
124 | * |
||
125 | * @param Structure $compared Structure to compare |
||
126 | * |
||
127 | * @return Structure Shortest structure |
||
128 | */ |
||
129 | 3 | private function getShortestStructure(Structure $compared): Structure |
|
133 | |||
134 | /** |
||
135 | * Define if string does not match any of the passed character groups. |
||
136 | * |
||
137 | * @param string $string String for comparison |
||
138 | * @param AbstractCG $initialGroup Initial character group |
||
139 | * @param AbstractCG $comparedGroup Compared character group |
||
140 | * |
||
141 | * @return bool True if string not matching any of character groups |
||
142 | */ |
||
143 | 3 | private function isStringNotMatchingAnyCG(string $string, AbstractCG $initialGroup, AbstractCG $comparedGroup): bool |
|
147 | |||
148 | /** |
||
149 | * @return string Structure input string |
||
150 | */ |
||
151 | 2 | public function getString(): string |
|
155 | } |
||
156 |