_wp_utf8_codepoint_span()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
_wp_utf8_codepoint_span( string $text, int $byte_offset, int $max_code_points, ?int $found_code_points ): int
Описание
Участки некорректных байтов считаются одной кодовой точкой согласно правилу максимальной подчасти. Эта функция является резервным методом для вызова strlen( mb_substr( substr( $text, $at ), 0, $max_code_points ) ).
Оригинал (английский)
Invalid spans of bytes count as a single code point according to the maximal subpart rule. This function is a fallback method for calling strlen( mb_substr( substr( $text, $at ), 0, $max_code_points ) ).
Параметры
$text
string
обязательный
$byte_offset
int
обязательный
$max_code_points
int
обязательный
$found_code_points
?int
необязательный
Возвращаемое значение
int
Исходный код
wp-includes/compat-utf8.php:381
function _wp_utf8_codepoint_span( string $text, int $byte_offset, int $max_code_points, ?int &$found_code_points = 0 ): int {
$was_at = $byte_offset;
$invalid_length = 0;
$end = strlen( $text );
$found_code_points = 0;
while ( $byte_offset < $end && $found_code_points < $max_code_points ) {
$needed = $max_code_points - $found_code_points;
$chunk_count = _wp_scan_utf8( $text, $byte_offset, $invalid_length, null, $needed );
$found_code_points += $chunk_count;
// Invalid spans only convey one code point count regardless of how long they are.
if ( 0 !== $invalid_length && $found_code_points < $max_code_points ) {
++$found_code_points;
$byte_offset += $invalid_length;
}
}
return $byte_offset - $was_at;
}
История изменений
| Версия | Описание |
|---|---|
| 6.9.0 | Introduced. |

