/[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.21 by sysadm, Sat Oct 18 14:15:35 2025 UTC Revision 1.24 by sysadm, Fri Oct 31 10:31:55 2025 UTC
# Line 1  Line 1 
1  <?php  <?php
2  function str_length(string $str) : int  function str_length(string $str, bool $skip_ctrl_seq = false) : int
3  {  {
4          $len = strlen($str);          $len = strlen($str);
5          $ret = 0;          $ret = 0;
# 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                    if ($c == "\r" || $c == "\7") // skip
12                    {
13                            continue;
14                    }
15    
16                    if ($skip_ctrl_seq && $c == "\033" && $i + 1 < $len && $str[$i + 1] == "[") // Skip control sequence
17                    {
18                            for ($i = $i + 2;
19                                    $i < $len && (ctype_digit($str[$i]) || $str[$i] == ';' || $str[$i] == '?');
20                                    $i++)
21                                    ;
22    
23                            if ($i < $len && $str[$i] == 'm') // valid
24                            {
25                                    // skip
26                            }
27                            else if ($i < $len && ctype_alpha($str[$i]))
28                            {
29                                    // unsupported ANSI CSI command
30                            }
31                            else
32                            {
33                                    $i--;
34                            }
35    
36                            continue;
37                    }
38    
39                  // Process UTF-8 Chinese characters                  // Process UTF-8 Chinese characters
40                  $v1 = ord($c);                  $v1 = ord($c);
41                  if ($v1 & 0x80) //head of multi-byte character                  if ($v1 & 0x80) //head of multi-byte character
# Line 31  function str_length(string $str) : int Line 59  function str_length(string $str) : int
59          return $ret;          return $ret;
60  }  }
61    
62  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
63  {  {
64          if ($width <= 0)          if ($width <= 0)
65          {          {
66                  return $str;                  $width = PHP_INT_MAX;
67          }          }
68    
69          $result = "";          $result = "";


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

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