--- lbbs/src/str_process.c 2025/11/08 08:21:31 1.28 +++ lbbs/src/str_process.c 2026/01/03 10:27:14 1.35 @@ -3,9 +3,13 @@ * str_process * - common string processing features with UTF-8 support * - * Copyright (C) 2004-2025 Leaflet + * Copyright (C) 2004-2026 Leaflet */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include "common.h" #include "log.h" #include "str_process.h" @@ -38,14 +42,14 @@ int str_length(const char *str, int skip if (skip_ctrl_seq && c == '\033' && str[i + 1] == '[') // Skip control sequence { - for (i = i + 2; isdigit(str[i]) || str[i] == ';' || str[i] == '?'; i++) + for (i = i + 2; isdigit((int)str[i]) || str[i] == ';' || str[i] == '?'; i++) ; if (str[i] == 'm') // valid { // skip } - else if (isalpha(str[i])) + else if (isalpha((int)str[i])) { // unsupported ANSI CSI command } @@ -72,9 +76,13 @@ int str_length(const char *str, int skip if (mbstowcs(wcs, input_str, 1) == (size_t)-1) { - log_error("mbstowcs(%s) error\n", input_str); + log_debug("mbstowcs(%s) error", input_str); + wc_len = (UTF8_fixed_width ? 2 : 1); // Fallback + } + else + { + wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); } - wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); i += (str_len - 1); ret += wc_len; @@ -132,9 +140,14 @@ int split_line(const char *buffer, int m if (mbstowcs(wcs, input_str, 1) == (size_t)-1) { - log_error("mbstowcs(%s) error\n", input_str); + log_debug("mbstowcs(%s) error", input_str); + wc_len = (UTF8_fixed_width ? 2 : 1); // Fallback } - wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); + else + { + wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); + } + if (*p_display_len + wc_len > max_display_len) { break; @@ -186,7 +199,7 @@ long split_data_lines(const char *p_buf, // Exceed max_line_cnt if (line_cnt + 1 >= line_offsets_count) { - // log_error("Line count %d reaches limit %d\n", line_cnt + 1, line_offsets_count); + log_debug("Line count %d reaches limit %d", line_cnt + 1, line_offsets_count); return line_cnt; }