--- lbbs/src/str_process.c 2025/10/18 12:06:10 1.21 +++ lbbs/src/str_process.c 2025/11/07 15:56:42 1.27 @@ -1,22 +1,15 @@ -/*************************************************************************** - str_process.c - description - ------------------- - Copyright : (C) 2004-2025 by Leaflet - Email : leaflet@leafok.com - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 3 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * str_process + * - common string processing features with UTF-8 support + * + * Copyright (C) 2004-2025 Leaflet + */ #include "common.h" #include "log.h" #include "str_process.h" +#include #include #include @@ -37,11 +30,22 @@ 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; } @@ -158,7 +162,7 @@ long split_data_lines(const char *p_buf, p_line_offsets[line_cnt + 1] = p_line_offsets[line_cnt] + len; line_cnt++; p_buf += len; - } while (p_buf[0] != '\0'); + } while (p_buf[0] != '\0' || end_of_line); return line_cnt; }