--- fenglin/lib/str_process.inc.php 2025/05/19 01:48:57 1.19 +++ fenglin/lib/str_process.inc.php 2025/10/30 11:19:14 1.22 @@ -10,15 +10,14 @@ function str_length(string $str) : int // Process UTF-8 Chinese characters $v1 = ord($c); - if (($v1 & 0b10000000) == 0b10000000) //head of multi-byte character + if ($v1 & 0x80) //head of multi-byte character { - $v2 = ($v1 & 0b01111000) << 1; - while ($v2 & 0b10000000) + $v2 = ($v1 & 0x70) << 1; + while ($v2 & 0x80) { $i++; - $v3 = $str[$i]; - $c .= $v3; - $v2 = ($v2 & 0b01111111 ) << 1; + $c .= $str[$i]; + $v2 = ($v2 & 0x7f) << 1; } $ret += 2; @@ -32,11 +31,11 @@ function str_length(string $str) : int return $ret; } -function split_line(string $str, string $prefix = "", int $width = 76, int $lines_limit = PHP_INT_MAX, string $end_of_line = "\n") : string +function split_line(string $str, string $prefix = "", int $width = PHP_INT_MAX, int $lines_limit = PHP_INT_MAX, string $end_of_line = "\n") : string { if ($width <= 0) { - return $str; + $width = PHP_INT_MAX; } $result = ""; @@ -73,15 +72,14 @@ function split_line(string $str, string // Process UTF-8 Chinese characters $v1 = ord($c); - if (($v1 & 0b10000000) == 0b10000000) //head of multi-byte character + if ($v1 & 0x80) //head of multi-byte character { - $v2 = ($v1 & 0b01111000) << 1; - while ($v2 & 0b10000000) + $v2 = ($v1 & 0x70) << 1; + while ($v2 & 0x80) { $i++; - $v3 = $str[$i]; - $c .= $v3; - $v2 = ($v2 & 0b01111111 ) << 1; + $c .= $str[$i]; + $v2 = ($v2 & 0x7f) << 1; } // Each UTF-8 CJK character should use two character length for display