1 | <?php |
||
10 | class ParsedText |
||
11 | { |
||
12 | /** |
||
13 | * @var bool Whether to decode HTML entities when decoding text |
||
14 | */ |
||
15 | public $decodeHtmlEntities = false; |
||
16 | |||
17 | /** |
||
18 | * @var bool Whether text contains escape characters |
||
19 | */ |
||
20 | protected $hasEscapedChars = false; |
||
21 | |||
22 | /** |
||
23 | * @var bool Whether text contains link references |
||
24 | */ |
||
25 | protected $hasReferences = false; |
||
26 | |||
27 | /** |
||
28 | * @var array Array of [label => link info] |
||
29 | */ |
||
30 | public $linkReferences = []; |
||
31 | |||
32 | /** |
||
33 | * @var string Text being parsed |
||
34 | */ |
||
35 | protected $text; |
||
36 | |||
37 | 263 | /** |
|
38 | * @param string $text Original text |
||
39 | 263 | */ |
|
40 | 263 | public function __construct($text) |
|
63 | |||
64 | 263 | /** |
|
65 | * @return string |
||
66 | 263 | */ |
|
67 | public function __toString() |
||
71 | |||
72 | /** |
||
73 | * Return the character at given position |
||
74 | * |
||
75 | * @param integer $pos |
||
76 | * @return string |
||
77 | 69 | */ |
|
78 | public function charAt($pos) |
||
82 | 1 | ||
83 | 69 | /** |
|
84 | * Decode a chunk of encoded text to be used as an attribute value |
||
85 | 69 | * |
|
86 | 69 | * Decodes escaped literals and removes slashes and 0x1A characters |
|
87 | 7 | * |
|
88 | 7 | * @param string $str Encoded text |
|
89 | * @return string Decoded text |
||
90 | 7 | */ |
|
91 | 7 | public function decode($str) |
|
114 | |||
115 | /** |
||
116 | * Find the first occurence of given substring starting at given position |
||
117 | * |
||
118 | 8 | * @param string $str |
|
119 | * @param integer $pos |
||
120 | 8 | * @return bool|integer |
|
121 | */ |
||
122 | public function indexOf($str, $pos = 0) |
||
126 | |||
127 | /** |
||
128 | * Test whether given position is preceded by whitespace |
||
129 | 59 | * |
|
130 | * @param integer $pos |
||
131 | 59 | * @return bool |
|
132 | */ |
||
133 | public function isAfterWhitespace($pos) |
||
137 | |||
138 | /** |
||
139 | * Test whether given character is alphanumeric |
||
140 | * |
||
141 | 8 | * @param string $chr |
|
142 | * @return bool |
||
143 | 8 | */ |
|
144 | public function isAlnum($chr) |
||
148 | |||
149 | /** |
||
150 | * Test whether given position is followed by whitespace |
||
151 | * |
||
152 | * @param integer $pos |
||
153 | * @return bool |
||
154 | 59 | */ |
|
155 | public function isBeforeWhitespace($pos) |
||
159 | |||
160 | /** |
||
161 | * Test whether a length of text is surrounded by alphanumeric characters |
||
162 | * |
||
163 | * @param integer $pos Start of the text |
||
164 | * @param integer $len Length of the text |
||
165 | 263 | * @return bool |
|
166 | */ |
||
167 | 263 | public function isSurroundedByAlnum($pos, $len) |
|
171 | |||
172 | /** |
||
173 | * Test whether given character is an ASCII whitespace character |
||
174 | * |
||
175 | * NOTE: newlines are normalized to LF before parsing so we don't have to check for CR |
||
176 | * |
||
177 | * @param string $chr |
||
178 | * @return bool |
||
179 | */ |
||
180 | public function isWhitespace($chr) |
||
184 | |||
185 | 130 | /** |
|
186 | * Mark the boundary of a block in the original text |
||
187 | * |
||
188 | * @param integer $pos |
||
189 | * @return void |
||
190 | */ |
||
191 | public function markBoundary($pos) |
||
195 | |||
196 | /** |
||
197 | * Overwrite part of the text with substitution characters ^Z (0x1A) |
||
198 | * |
||
199 | * @param integer $pos Start of the range |
||
200 | * @param integer $len Length of text to overwrite |
||
201 | * @return void |
||
202 | */ |
||
203 | public function overwrite($pos, $len) |
||
210 | } |