WP_Block_Processor::find_html_comment_endprivateWP 6.9.0

Returns the byte-offset after the ending character of an HTML comment, assuming the proper starting byte offset.

Метод класса: WP_Block_Processor{}

Хуков нет.

Возвращает

int. Offset after the current HTML comment ends, or $search_end if no end was found.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->find_html_comment_end( $comment_starting_at, $search_end ): int;
$comment_starting_at(int) (обязательный)
Where the HTML comment started, the leading <.
$search_end(int) (обязательный)
Last offset in which to search, for limiting search span.

Список изменений

С версии 6.9.0 Введена.

Код WP_Block_Processor::find_html_comment_end() WP 6.9.1

private function find_html_comment_end( int $comment_starting_at, int $search_end ): int {
	$text = $this->source_text;

	// Find span-of-dashes comments which look like `<!----->`.
	$span_of_dashes = strspn( $text, '-', $comment_starting_at + 2 );
	if (
		$comment_starting_at + 2 + $span_of_dashes < $search_end &&
		'>' === $text[ $comment_starting_at + 2 + $span_of_dashes ]
	) {
		return $comment_starting_at + $span_of_dashes + 1;
	}

	// Otherwise, there are other characters inside the comment, find the first `-->` or `--!>`.
	$now_at = $comment_starting_at + 4;
	while ( $now_at < $search_end ) {
		$dashes_at = strpos( $text, '--', $now_at );
		if ( false === $dashes_at ) {
			return $search_end;
		}

		$closer_must_be_at = $dashes_at + 2 + strspn( $text, '-', $dashes_at + 2 );
		if ( $closer_must_be_at < $search_end && '!' === $text[ $closer_must_be_at ] ) {
			++$closer_must_be_at;
		}

		if ( $closer_must_be_at < $search_end && '>' === $text[ $closer_must_be_at ] ) {
			return $closer_must_be_at + 1;
		}

		++$now_at;
	}

	return $search_end;
}