/[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.12 by sysadm, Wed Mar 26 07:09:08 2025 UTC Revision 1.18 by sysadm, Tue Apr 29 11:55:32 2025 UTC
# Line 1  Line 1 
1  <?  <?php
2  function str_length($str)  function str_length(string $str) : string
3  {  {
4          $len = strlen($str);          $len = strlen($str);
5          $ret = 0;          $ret = 0;
# Line 32  function str_length($str) Line 32  function str_length($str)
32          return $ret;          return $ret;
33  }  }
34    
35  function split_line($str, $prefix = "", $width = 76, $lines_limit = PHP_INT_MAX)  function split_line(string $str, string $prefix = "", int $width = 76, int $lines_limit = PHP_INT_MAX, string $end_of_line = "\n") : string
36  {  {
37          if ($width <= 0)          if ($width <= 0)
38            {
39                  return $str;                  return $str;
40                    }
41    
42          $result = "";          $result = "";
43          $len = strlen($str);          $len = strlen($str);
44          $prefix_len = str_length($prefix);          $prefix_len = str_length($prefix);
# Line 54  function split_line($str, $prefix = "", Line 56  function split_line($str, $prefix = "",
56                  {                  {
57                          continue;                          continue;
58                  }                  }
59                                    
60                  if ($c == "\n")                  if ($c == "\n")
61                  {                  {
62                          $result .= ($line . "\n");                          if ($lines_count + 1 >= $lines_limit)
63                            {
64                                    break;
65                            }
66    
67                            $result .= ($line . $end_of_line);
68                          $lines_count++;                          $lines_count++;
69                          $line = $prefix;                          $line = $prefix;
70                          $line_len = $prefix_len;                          $line_len = $prefix_len;
# Line 85  function split_line($str, $prefix = "", Line 92  function split_line($str, $prefix = "",
92                                          break;                                          break;
93                                  }                                  }
94    
95                                  $result .= ($line . "\n");                                  $result .= ($line . $end_of_line);
96                                  $lines_count++;                                  $lines_count++;
97                                  $line = $prefix;                                  $line = $prefix;
98                                  $line_len = $prefix_len;                                  $line_len = $prefix_len;
# Line 97  function split_line($str, $prefix = "", Line 104  function split_line($str, $prefix = "",
104                          $line_len++;                          $line_len++;
105                  }                  }
106    
107                  $line .= $c;                  if ($line_len > $width)
   
                 if ($line_len >= $width)  
108                  {                  {
109                          if ($lines_count + 1 >= $lines_limit)                          if ($lines_count + 1 >= $lines_limit)
110                          {                          {
111                                  break;                                  break;
112                          }                          }
113    
114                          $result .= ($line . "\n");                          $result .= ($line . $end_of_line);
115                          $lines_count++;                          $lines_count++;
116                          $line = $prefix;                          $line = $prefix;
117                          $line_len = $prefix_len;                          $line_len = $prefix_len + 1;
118                  }                  }
119    
120                    $line .= $c;
121          }          }
122    
123          if ($lines_count < $lines_limit)          if ($lines_count < $lines_limit)
# Line 120  function split_line($str, $prefix = "", Line 127  function split_line($str, $prefix = "",
127    
128          return $result;          return $result;
129  }  }
 ?>  


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

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