/[LeafOK_CVS]/lbbs/utils/lib/str_process.inc.php
ViewVC logotype

Diff of /lbbs/utils/lib/str_process.inc.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.2 by sysadm, Mon May 19 01:47:28 2025 UTC Revision 1.3 by sysadm, Wed Jul 2 04:17:33 2025 UTC
# Line 8  function str_length(string $str) : int Line 8  function str_length(string $str) : int
8          {          {
9                  $c = $str[$i];                  $c = $str[$i];
10    
11                  // Process GBK Chinese characters                  // Process UTF-8 Chinese characters
12                  $v1 = ord($c);                  $v1 = ord($c);
13                  if ($v1 > 127 && $v1 <= 255) // GBK chinese character                  if ($v1 & 0b10000000) //head of multi-byte character
14                  {                  {
15                          $i++;                          $v2 = ($v1 & 0b01110000) << 1;
16                          $c .= $str[$i];                          while ($v2 & 0b10000000)
17                            {
18                                    $i++;
19                                    $c .= $str[$i];
20                                    $v2 = ($v2 & 0b01111111) << 1;
21                            }
22    
23                          $ret += 2;                          $ret += 2;
24                  }                  }
# Line 65  function split_line(string $str, string Line 70  function split_line(string $str, string
70                          continue;                          continue;
71                  }                  }
72    
73                  // Process GBK Chinese characters                  // Process UTF-8 Chinese characters
74                  $v1 = ord($c);                  $v1 = ord($c);
75                  if ($v1 > 127 && $v1 <= 255) // GBK chinese character                  if ($v1 & 0b10000000) //head of multi-byte character
76                  {                  {
77                          $i++;                          $v2 = ($v1 & 0b01110000) << 1;
78                          $c .= $str[$i];                          while ($v2 & 0b10000000)
79                            {
80                                    $i++;
81                                    $c .= $str[$i];
82                                    $v2 = ($v2 & 0b01111111) << 1;
83                            }
84    
85                          // Each GBK CJK character should use two character length for display                          // Each UTF-8 CJK character should use two character length for display
86                          if ($line_len + 2 > $width)                          if ($line_len + 2 > $width)
87                          {                          {
88                                  if ($lines_count + 1 >= $lines_limit)                                  if ($lines_count + 1 >= $lines_limit)


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1