diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2024-12-17 10:01:17 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2024-12-17 10:01:17 +0000 |
| commit | d523e7a676d6d2cdda0369fac3dc9f953d3a4e96 (patch) | |
| tree | 83e918c6a0f53c7c05f9350be818bbc456666e14 /misc.c | |
| parent | box-drawings: implement octants (diff) | |
term: set_app_id() + set_window_title(): only allow printable characters
Diffstat (limited to 'misc.c')
| -rw-r--r-- | misc.c | 17 |
1 files changed, 14 insertions, 3 deletions
@@ -44,8 +44,19 @@ timespec_sub(const struct timespec *a, const struct timespec *b, } bool -is_valid_utf8(const char *value) +is_valid_utf8_and_printable(const char *value) { - return value != NULL && - mbsntoc32(NULL, value, strlen(value), 0) != (size_t)-1; + char32_t *wide = ambstoc32(value); + if (wide == NULL) + return false; + + for (const char32_t *c = wide; *c != U'\0'; c++) { + if (!isc32print(*c)) { + free(wide); + return false; + } + } + + free(wide); + return true; } |
