/[LeafOK_CVS]/fenglin/lib/str_process.inc.php
ViewVC logotype

Diff of /fenglin/lib/str_process.inc.php

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

Revision 1.15 by sysadm, Mon Apr 7 06:26:44 2025 UTC Revision 1.20 by sysadm, Wed Jul 2 02:00:57 2025 UTC
# Line 1  Line 1 
1  <?  <?php
2  function str_length(string $str) : string  function str_length(string $str) : int
3  {  {
4          $len = strlen($str);          $len = strlen($str);
5          $ret = 0;          $ret = 0;
# Line 10  function str_length(string $str) : strin Line 10  function str_length(string $str) : strin
10    
11                  // Process UTF-8 Chinese characters                  // Process UTF-8 Chinese characters
12                  $v1 = ord($c);                  $v1 = ord($c);
13                  if (($v1 & 0b10000000) == 0b10000000) //head of multi-byte character                  if ($v1 & 0b10000000) //head of multi-byte character
14                  {                  {
15                          $v2 = ($v1 & 0b01111000) << 1;                          $v2 = ($v1 & 0b01110000) << 1;
16                          while ($v2 & 0b10000000)                          while ($v2 & 0b10000000)
17                          {                          {
18                                  $i++;                                  $i++;
19                                  $v3 = $str[$i];                                  $c .= $str[$i];
20                                  $c .= $v3;                                  $v2 = ($v2 & 0b01111111) << 1;
                                 $v2 = ($v2 & 0b01111111 ) << 1;  
21                          }                          }
22    
23                          $ret += 2;                          $ret += 2;
# Line 38  function split_line(string $str, string Line 37  function split_line(string $str, string
37          {          {
38                  return $str;                  return $str;
39          }          }
40            
41          $result = "";          $result = "";
42          $len = strlen($str);          $len = strlen($str);
43          $prefix_len = str_length($prefix);          $prefix_len = str_length($prefix);
# Line 56  function split_line(string $str, string Line 55  function split_line(string $str, string
55                  {                  {
56                          continue;                          continue;
57                  }                  }
58                                    
59                  if ($c == "\n")                  if ($c == "\n")
60                  {                  {
61                          if ($lines_count + 1 >= $lines_limit)                          if ($lines_count + 1 >= $lines_limit)
# Line 73  function split_line(string $str, string Line 72  function split_line(string $str, string
72    
73                  // Process UTF-8 Chinese characters                  // Process UTF-8 Chinese characters
74                  $v1 = ord($c);                  $v1 = ord($c);
75                  if (($v1 & 0b10000000) == 0b10000000) //head of multi-byte character                  if ($v1 & 0b10000000) //head of multi-byte character
76                  {                  {
77                          $v2 = ($v1 & 0b01111000) << 1;                          $v2 = ($v1 & 0b01110000) << 1;
78                          while ($v2 & 0b10000000)                          while ($v2 & 0b10000000)
79                          {                          {
80                                  $i++;                                  $i++;
81                                  $v3 = $str[$i];                                  $c .= $str[$i];
82                                  $c .= $v3;                                  $v2 = ($v2 & 0b01111111) << 1;
                                 $v2 = ($v2 & 0b01111111 ) << 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
# Line 127  function split_line(string $str, string Line 125  function split_line(string $str, string
125    
126          return $result;          return $result;
127  }  }
 ?>  


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

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