--- lbbs/src/str_process.c 2025/07/02 04:17:33 1.20 +++ lbbs/src/str_process.c 2025/10/31 06:04:17 1.22 @@ -17,6 +17,7 @@ #include "common.h" #include "log.h" #include "str_process.h" +#include #include #include @@ -37,22 +38,33 @@ int str_length(const char *str, int skip if (skip_ctrl_seq && c == '\033' && str[i + 1] == '[') // Skip control sequence { - i += 2; - while (str[i] != '\0' && str[i] != 'm') + for (i = i + 2; isdigit(str[i]) || str[i] == ';' || str[i] == '?'; i++) + ; + + if (str[i] == 'm') // valid { - i++; + // skip + } + else if (isalpha(str[i])) + { + // unsupported ANSI CSI command + } + else + { + i--; } + continue; } // Process UTF-8 Chinese characters - if (c & 0b10000000) // head of multi-byte character + if (c & 0x80) // head of multi-byte character { - c = (c & 0b01110000) << 1; - while (c & 0b10000000) + c = (c & 0x70) << 1; + while (c & 0x80) { i++; - c = (c & 0b01111111) << 1; + c = (c & 0x7f) << 1; } ret += 2; @@ -92,18 +104,18 @@ int split_line(const char *buffer, int m continue; } - if (c & 0b10000000) // head of multi-byte character + if (c & 0x80) // head of multi-byte character { if (*p_display_len + 2 > max_display_len) { break; } - c = (c & 0b01110000) << 1; - while (c & 0b10000000) + c = (c & 0x70) << 1; + while (c & 0x80) { i++; - c = (c & 0b01111111) << 1; + c = (c & 0x7f) << 1; } (*p_display_len) += 2;