Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d515007

Browse files
kitrioezyang
andauthored
refactor: #414 remove method substrCount (#415)
Co-authored-by: Edward Z. Yang <[email protected]>
1 parent b5cbf0c commit d515007

1 file changed

Lines changed: 7 additions & 29 deletions

File tree

library/HTMLPurifier/Lexer/DirectLex.php

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function tokenizeHTML($html, $config, $context)
111111
if ($synchronize_interval && // synchronization is on
112112
$cursor > 0 && // cursor is further than zero
113113
$loops % $synchronize_interval === 0) { // time to synchronize!
114-
$current_line = 1 + $this->substrCount($html, $nl, 0, $cursor);
114+
$current_line = 1 + substr_count($html, $nl, 0, $cursor);
115115
}
116116
}
117117

@@ -139,7 +139,7 @@ public function tokenizeHTML($html, $config, $context)
139139
);
140140
if ($maintain_line_numbers) {
141141
$token->rawPosition($current_line, $current_col);
142-
$current_line += $this->substrCount($html, $nl, $cursor, $position_next_lt - $cursor);
142+
$current_line += substr_count($html, $nl, $cursor, $position_next_lt - $cursor);
143143
}
144144
$array[] = $token;
145145
$cursor = $position_next_lt + 1;
@@ -214,7 +214,7 @@ public function tokenizeHTML($html, $config, $context)
214214
);
215215
if ($maintain_line_numbers) {
216216
$token->rawPosition($current_line, $current_col);
217-
$current_line += $this->substrCount($html, $nl, $cursor, $strlen_segment);
217+
$current_line += substr_count($html, $nl, $cursor, $strlen_segment);
218218
}
219219
$array[] = $token;
220220
$cursor = $end ? $position_comment_end : $position_comment_end + 3;
@@ -229,7 +229,7 @@ public function tokenizeHTML($html, $config, $context)
229229
$token = new HTMLPurifier_Token_End($type);
230230
if ($maintain_line_numbers) {
231231
$token->rawPosition($current_line, $current_col);
232-
$current_line += $this->substrCount($html, $nl, $cursor, $position_next_gt - $cursor);
232+
$current_line += substr_count($html, $nl, $cursor, $position_next_gt - $cursor);
233233
}
234234
$array[] = $token;
235235
$inside_tag = false;
@@ -248,7 +248,7 @@ public function tokenizeHTML($html, $config, $context)
248248
$token = new HTMLPurifier_Token_Text('<');
249249
if ($maintain_line_numbers) {
250250
$token->rawPosition($current_line, $current_col);
251-
$current_line += $this->substrCount($html, $nl, $cursor, $position_next_gt - $cursor);
251+
$current_line += substr_count($html, $nl, $cursor, $position_next_gt - $cursor);
252252
}
253253
$array[] = $token;
254254
$inside_tag = false;
@@ -276,7 +276,7 @@ public function tokenizeHTML($html, $config, $context)
276276
}
277277
if ($maintain_line_numbers) {
278278
$token->rawPosition($current_line, $current_col);
279-
$current_line += $this->substrCount($html, $nl, $cursor, $position_next_gt - $cursor);
279+
$current_line += substr_count($html, $nl, $cursor, $position_next_gt - $cursor);
280280
}
281281
$array[] = $token;
282282
$inside_tag = false;
@@ -310,7 +310,7 @@ public function tokenizeHTML($html, $config, $context)
310310
}
311311
if ($maintain_line_numbers) {
312312
$token->rawPosition($current_line, $current_col);
313-
$current_line += $this->substrCount($html, $nl, $cursor, $position_next_gt - $cursor);
313+
$current_line += substr_count($html, $nl, $cursor, $position_next_gt - $cursor);
314314
}
315315
$array[] = $token;
316316
$cursor = $position_next_gt + 1;
@@ -343,28 +343,6 @@ public function tokenizeHTML($html, $config, $context)
343343
return $array;
344344
}
345345

346-
/**
347-
* PHP 5.0.x compatible substr_count that implements offset and length
348-
* @param string $haystack
349-
* @param string $needle
350-
* @param int $offset
351-
* @param int $length
352-
* @return int
353-
*/
354-
protected function substrCount($haystack, $needle, $offset, $length)
355-
{
356-
static $oldVersion;
357-
if ($oldVersion === null) {
358-
$oldVersion = version_compare(PHP_VERSION, '5.1', '<');
359-
}
360-
if ($oldVersion) {
361-
$haystack = substr($haystack, $offset, $length);
362-
return substr_count($haystack, $needle);
363-
} else {
364-
return substr_count($haystack, $needle, $offset, $length);
365-
}
366-
}
367-
368346
/**
369347
* Takes the inside of an HTML tag and makes an assoc array of attributes.
370348
*

0 commit comments

Comments
 (0)