| 3 |
* str_process |
* str_process |
| 4 |
* - common string processing features with UTF-8 support |
* - common string processing features with UTF-8 support |
| 5 |
* |
* |
| 6 |
* Copyright (C) 2004-2025 Leaflet <leaflet@leafok.com> |
* Copyright (C) 2004-2026 Leaflet <leaflet@leafok.com> |
| 7 |
*/ |
*/ |
| 8 |
|
|
| 9 |
|
#ifdef HAVE_CONFIG_H |
| 10 |
|
#include "config.h" |
| 11 |
|
#endif |
| 12 |
|
|
| 13 |
#include "common.h" |
#include "common.h" |
| 14 |
#include "log.h" |
#include "log.h" |
| 15 |
#include "str_process.h" |
#include "str_process.h" |
| 42 |
|
|
| 43 |
if (skip_ctrl_seq && c == '\033' && str[i + 1] == '[') // Skip control sequence |
if (skip_ctrl_seq && c == '\033' && str[i + 1] == '[') // Skip control sequence |
| 44 |
{ |
{ |
| 45 |
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++) |
| 46 |
; |
; |
| 47 |
|
|
| 48 |
if (str[i] == 'm') // valid |
if (str[i] == 'm') // valid |
| 49 |
{ |
{ |
| 50 |
// skip |
// skip |
| 51 |
} |
} |
| 52 |
else if (isalpha(str[i])) |
else if (isalpha((int)str[i])) |
| 53 |
{ |
{ |
| 54 |
// unsupported ANSI CSI command |
// unsupported ANSI CSI command |
| 55 |
} |
} |
| 76 |
|
|
| 77 |
if (mbstowcs(wcs, input_str, 1) == (size_t)-1) |
if (mbstowcs(wcs, input_str, 1) == (size_t)-1) |
| 78 |
{ |
{ |
| 79 |
#ifdef _DEBUG |
log_debug("mbstowcs(%s) error", input_str); |
|
log_error("mbstowcs(%s) error\n", input_str); |
|
|
#endif |
|
| 80 |
wc_len = (UTF8_fixed_width ? 2 : 1); // Fallback |
wc_len = (UTF8_fixed_width ? 2 : 1); // Fallback |
| 81 |
} |
} |
| 82 |
else |
else |
| 140 |
|
|
| 141 |
if (mbstowcs(wcs, input_str, 1) == (size_t)-1) |
if (mbstowcs(wcs, input_str, 1) == (size_t)-1) |
| 142 |
{ |
{ |
| 143 |
#ifdef _DEBUG |
log_debug("mbstowcs(%s) error", input_str); |
|
log_error("mbstowcs(%s) error\n", input_str); |
|
|
#endif |
|
| 144 |
wc_len = (UTF8_fixed_width ? 2 : 1); // Fallback |
wc_len = (UTF8_fixed_width ? 2 : 1); // Fallback |
| 145 |
} |
} |
| 146 |
else |
else |
| 199 |
// Exceed max_line_cnt |
// Exceed max_line_cnt |
| 200 |
if (line_cnt + 1 >= line_offsets_count) |
if (line_cnt + 1 >= line_offsets_count) |
| 201 |
{ |
{ |
| 202 |
// 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); |
| 203 |
return line_cnt; |
return line_cnt; |
| 204 |
} |
} |
| 205 |
|
|