Skip to content

Commit

Permalink
Remove: ezyang#414 method substrCount
Browse files Browse the repository at this point in the history
  • Loading branch information
kitrio committed Aug 15, 2024
1 parent f0fbf51 commit 753f60f
Showing 1 changed file with 7 additions and 29 deletions.
36 changes: 7 additions & 29 deletions library/HTMLPurifier/Lexer/DirectLex.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function tokenizeHTML($html, $config, $context)
if ($synchronize_interval && // synchronization is on
$cursor > 0 && // cursor is further than zero
$loops % $synchronize_interval === 0) { // time to synchronize!
$current_line = 1 + $this->substrCount($html, $nl, 0, $cursor);
$current_line = 1 + substr_count($html, $nl, 0, $cursor);
}
}

Expand Down Expand Up @@ -139,7 +139,7 @@ public function tokenizeHTML($html, $config, $context)
);
if ($maintain_line_numbers) {
$token->rawPosition($current_line, $current_col);
$current_line += $this->substrCount($html, $nl, $cursor, $position_next_lt - $cursor);
$current_line += substr_count($html, $nl, $cursor, $position_next_lt - $cursor);
}
$array[] = $token;
$cursor = $position_next_lt + 1;
Expand Down Expand Up @@ -214,7 +214,7 @@ public function tokenizeHTML($html, $config, $context)
);
if ($maintain_line_numbers) {
$token->rawPosition($current_line, $current_col);
$current_line += $this->substrCount($html, $nl, $cursor, $strlen_segment);
$current_line += substr_count($html, $nl, $cursor, $strlen_segment);
}
$array[] = $token;
$cursor = $end ? $position_comment_end : $position_comment_end + 3;
Expand All @@ -229,7 +229,7 @@ public function tokenizeHTML($html, $config, $context)
$token = new HTMLPurifier_Token_End($type);
if ($maintain_line_numbers) {
$token->rawPosition($current_line, $current_col);
$current_line += $this->substrCount($html, $nl, $cursor, $position_next_gt - $cursor);
$current_line += substr_count($html, $nl, $cursor, $position_next_gt - $cursor);
}
$array[] = $token;
$inside_tag = false;
Expand All @@ -248,7 +248,7 @@ public function tokenizeHTML($html, $config, $context)
$token = new HTMLPurifier_Token_Text('<');
if ($maintain_line_numbers) {
$token->rawPosition($current_line, $current_col);
$current_line += $this->substrCount($html, $nl, $cursor, $position_next_gt - $cursor);
$current_line += substr_count($html, $nl, $cursor, $position_next_gt - $cursor);
}
$array[] = $token;
$inside_tag = false;
Expand Down Expand Up @@ -276,7 +276,7 @@ public function tokenizeHTML($html, $config, $context)
}
if ($maintain_line_numbers) {
$token->rawPosition($current_line, $current_col);
$current_line += $this->substrCount($html, $nl, $cursor, $position_next_gt - $cursor);
$current_line += substr_count($html, $nl, $cursor, $position_next_gt - $cursor);
}
$array[] = $token;
$inside_tag = false;
Expand Down Expand Up @@ -310,7 +310,7 @@ public function tokenizeHTML($html, $config, $context)
}
if ($maintain_line_numbers) {
$token->rawPosition($current_line, $current_col);
$current_line += $this->substrCount($html, $nl, $cursor, $position_next_gt - $cursor);
$current_line += substr_count($html, $nl, $cursor, $position_next_gt - $cursor);
}
$array[] = $token;
$cursor = $position_next_gt + 1;
Expand Down Expand Up @@ -343,28 +343,6 @@ public function tokenizeHTML($html, $config, $context)
return $array;
}

/**
* PHP 5.0.x compatible substr_count that implements offset and length
* @param string $haystack
* @param string $needle
* @param int $offset
* @param int $length
* @return int
*/
protected function substrCount($haystack, $needle, $offset, $length)
{
static $oldVersion;
if ($oldVersion === null) {
$oldVersion = version_compare(PHP_VERSION, '5.1', '<');
}
if ($oldVersion) {
$haystack = substr($haystack, $offset, $length);
return substr_count($haystack, $needle);
} else {
return substr_count($haystack, $needle, $offset, $length);
}
}

/**
* Takes the inside of an HTML tag and makes an assoc array of attributes.
*
Expand Down

0 comments on commit 753f60f

Please sign in to comment.