1 | <?php |
||
12 | class ParsedText implements ArrayAccess |
||
13 | { |
||
14 | /** |
||
15 | * @var bool Whether to decode HTML entities when decoding text |
||
16 | */ |
||
17 | public $decodeHtmlEntities = false; |
||
18 | |||
19 | /** |
||
20 | * @var bool Whether text contains escape characters |
||
21 | */ |
||
22 | protected $hasEscapedChars = false; |
||
23 | |||
24 | /** |
||
25 | * @var array Array of [label => link info] |
||
26 | */ |
||
27 | public $linkReferences = []; |
||
28 | |||
29 | /** |
||
30 | * @var string Text being parsed |
||
31 | */ |
||
32 | protected $text; |
||
33 | |||
34 | /** |
||
35 | * @param string $text Original text |
||
36 | */ |
||
37 | 263 | public function __construct($text) |
|
60 | |||
61 | /** |
||
62 | * @return string |
||
63 | */ |
||
64 | 263 | public function __toString() |
|
68 | |||
69 | /** |
||
70 | * Decode a chunk of encoded text to be used as an attribute value |
||
71 | * |
||
72 | * Decodes escaped literals and removes slashes and 0x1A characters |
||
73 | * |
||
74 | * @param string $str Encoded text |
||
75 | * @return string Decoded text |
||
76 | */ |
||
77 | 69 | public function decode($str) |
|
100 | |||
101 | /** |
||
102 | * Test whether given position is preceded by whitespace |
||
103 | * |
||
104 | * @param integer $pos |
||
105 | * @return bool |
||
106 | */ |
||
107 | 59 | public function isAfterWhitespace($pos) |
|
111 | |||
112 | /** |
||
113 | * Test whether given character is alphanumeric |
||
114 | * |
||
115 | * @param string $chr |
||
116 | * @return bool |
||
117 | */ |
||
118 | 8 | public function isAlnum($chr) |
|
122 | |||
123 | /** |
||
124 | * Test whether given position is followed by whitespace |
||
125 | * |
||
126 | * @param integer $pos |
||
127 | * @return bool |
||
128 | */ |
||
129 | 59 | public function isBeforeWhitespace($pos) |
|
133 | |||
134 | /** |
||
135 | * Test whether a length of text is surrounded by alphanumeric characters |
||
136 | * |
||
137 | * @param integer $pos Start of the text |
||
138 | * @param integer $len Length of the text |
||
139 | * @return bool |
||
140 | */ |
||
141 | 8 | public function isSurroundedByAlnum($pos, $len) |
|
145 | |||
146 | /** |
||
147 | * Test whether given character is an ASCII whitespace character |
||
148 | * |
||
149 | * NOTE: newlines are normalized to LF before parsing so we don't have to check for CR |
||
150 | * |
||
151 | * @param string $chr |
||
152 | * @return bool |
||
153 | */ |
||
154 | 59 | public function isWhitespace($chr) |
|
158 | |||
159 | /** |
||
160 | * Mark the boundary of a block in the original text |
||
161 | * |
||
162 | * @param integer $pos |
||
163 | * @return void |
||
164 | */ |
||
165 | 263 | public function markBoundary($pos) |
|
169 | |||
170 | /** |
||
171 | * @param mixed $offset |
||
172 | * @return bool |
||
173 | */ |
||
174 | public function offsetExists($offset) |
||
178 | |||
179 | /** |
||
180 | * @param mixed $offset |
||
181 | * @return string |
||
182 | */ |
||
183 | 130 | public function offsetGet($offset) |
|
187 | |||
188 | /** |
||
189 | * @param mixed $offset |
||
190 | * @param string $offset |
||
191 | * @return void |
||
192 | */ |
||
193 | public function offsetSet($offset, $value) |
||
197 | |||
198 | /** |
||
199 | * @param mixed $offset |
||
200 | * @return void |
||
201 | */ |
||
202 | public function offsetUnset($offset) |
||
206 | |||
207 | /** |
||
208 | * Overwrite part of the text with substitution characters ^Z (0x1A) |
||
209 | * |
||
210 | * @param integer $pos Start of the range |
||
211 | * @param integer $len Length of text to overwrite |
||
212 | * @return void |
||
213 | */ |
||
214 | 169 | public function overwrite($pos, $len) |
|
221 | } |