| 10 |
|
|
| 11 |
// Process UTF-8 Chinese characters |
// Process UTF-8 Chinese characters |
| 12 |
$v1 = ord($c); |
$v1 = ord($c); |
| 13 |
if ($v1 & 0b10000000) //head of multi-byte character |
if ($v1 & 0x80) //head of multi-byte character |
| 14 |
{ |
{ |
| 15 |
$v2 = ($v1 & 0b01110000) << 1; |
$v2 = ($v1 & 0x70) << 1; |
| 16 |
while ($v2 & 0b10000000) |
while ($v2 & 0x80) |
| 17 |
{ |
{ |
| 18 |
$i++; |
$i++; |
| 19 |
$c .= $str[$i]; |
$c .= $str[$i]; |
| 20 |
$v2 = ($v2 & 0b01111111) << 1; |
$v2 = ($v2 & 0x7f) << 1; |
| 21 |
} |
} |
| 22 |
|
|
| 23 |
$ret += 2; |
$ret += 2; |
| 31 |
return $ret; |
return $ret; |
| 32 |
} |
} |
| 33 |
|
|
| 34 |
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 |
| 35 |
{ |
{ |
| 36 |
if ($width <= 0) |
if ($width <= 0) |
| 37 |
{ |
{ |
| 38 |
return $str; |
$width = PHP_INT_MAX; |
| 39 |
} |
} |
| 40 |
|
|
| 41 |
$result = ""; |
$result = ""; |
| 72 |
|
|
| 73 |
// Process UTF-8 Chinese characters |
// Process UTF-8 Chinese characters |
| 74 |
$v1 = ord($c); |
$v1 = ord($c); |
| 75 |
if ($v1 & 0b10000000) //head of multi-byte character |
if ($v1 & 0x80) //head of multi-byte character |
| 76 |
{ |
{ |
| 77 |
$v2 = ($v1 & 0b01110000) << 1; |
$v2 = ($v1 & 0x70) << 1; |
| 78 |
while ($v2 & 0b10000000) |
while ($v2 & 0x80) |
| 79 |
{ |
{ |
| 80 |
$i++; |
$i++; |
| 81 |
$c .= $str[$i]; |
$c .= $str[$i]; |
| 82 |
$v2 = ($v2 & 0b01111111) << 1; |
$v2 = ($v2 & 0x7f) << 1; |
| 83 |
} |
} |
| 84 |
|
|
| 85 |
// Each UTF-8 CJK character should use two character length for display |
// Each UTF-8 CJK character should use two character length for display |