/[LeafOK_CVS]/lbbs/src/str_process.c
ViewVC logotype

Diff of /lbbs/src/str_process.c

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

Revision 1.20 by sysadm, Wed Jul 2 04:17:33 2025 UTC Revision 1.22 by sysadm, Fri Oct 31 06:04:17 2025 UTC
# Line 17  Line 17 
17  #include "common.h"  #include "common.h"
18  #include "log.h"  #include "log.h"
19  #include "str_process.h"  #include "str_process.h"
20    #include <ctype.h>
21  #include <stdio.h>  #include <stdio.h>
22  #include <string.h>  #include <string.h>
23    
# Line 37  int str_length(const char *str, int skip Line 38  int str_length(const char *str, int skip
38    
39                  if (skip_ctrl_seq && c == '\033' && str[i + 1] == '[') // Skip control sequence                  if (skip_ctrl_seq && c == '\033' && str[i + 1] == '[') // Skip control sequence
40                  {                  {
41                          i += 2;                          for (i = i + 2; isdigit(str[i]) || str[i] == ';' || str[i] == '?'; i++)
42                          while (str[i] != '\0' && str[i] != 'm')                                  ;
43    
44                            if (str[i] == 'm') // valid
45                          {                          {
46                                  i++;                                  // skip
47                            }
48                            else if (isalpha(str[i]))
49                            {
50                                    // unsupported ANSI CSI command
51                            }
52                            else
53                            {
54                                    i--;
55                          }                          }
56    
57                          continue;                          continue;
58                  }                  }
59    
60                  // Process UTF-8 Chinese characters                  // Process UTF-8 Chinese characters
61                  if (c & 0b10000000) // head of multi-byte character                  if (c & 0x80) // head of multi-byte character
62                  {                  {
63                          c = (c & 0b01110000) << 1;                          c = (c & 0x70) << 1;
64                          while (c & 0b10000000)                          while (c & 0x80)
65                          {                          {
66                                  i++;                                  i++;
67                                  c = (c & 0b01111111) << 1;                                  c = (c & 0x7f) << 1;
68                          }                          }
69    
70                          ret += 2;                          ret += 2;
# Line 92  int split_line(const char *buffer, int m Line 104  int split_line(const char *buffer, int m
104                          continue;                          continue;
105                  }                  }
106    
107                  if (c & 0b10000000) // head of multi-byte character                  if (c & 0x80) // head of multi-byte character
108                  {                  {
109                          if (*p_display_len + 2 > max_display_len)                          if (*p_display_len + 2 > max_display_len)
110                          {                          {
111                                  break;                                  break;
112                          }                          }
113    
114                          c = (c & 0b01110000) << 1;                          c = (c & 0x70) << 1;
115                          while (c & 0b10000000)                          while (c & 0x80)
116                          {                          {
117                                  i++;                                  i++;
118                                  c = (c & 0b01111111) << 1;                                  c = (c & 0x7f) << 1;
119                          }                          }
120    
121                          (*p_display_len) += 2;                          (*p_display_len) += 2;


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

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