diff options
author | Phil Jones <philj56@gmail.com> | 2022-10-23 13:24:48 +0100 |
---|---|---|
committer | Phil Jones <philj56@gmail.com> | 2022-10-23 13:24:59 +0100 |
commit | 3bbd8ff839354a6f488c8481d5e6336a3f637cee (patch) | |
tree | f793acfea9c8115d30bd00d1a7dde5fc9fc079d7 /src/config.c | |
parent | dd3a4a84d6676b51025e8feeb7af662a07b1e73c (diff) |
Replace wchar and friends with Unicode handling.
All text handling should now be explicitly UTF-8 or UTF-32, removing the
ambiguity around wchar_t and related functions.
Diffstat (limited to 'src/config.c')
-rw-r--r-- | src/config.c | 34 |
1 files changed, 11 insertions, 23 deletions
diff --git a/src/config.c b/src/config.c index 4305c3e..1fca428 100644 --- a/src/config.c +++ b/src/config.c @@ -10,6 +10,7 @@ #include "config.h" #include "log.h" #include "nelem.h" +#include "unicode.h" #include "xmalloc.h" /* Maximum number of config file errors before we give up */ @@ -77,7 +78,7 @@ static uint32_t fixup_percentage(uint32_t value, uint32_t base, bool is_percent, static uint32_t parse_anchor(const char *filename, size_t lineno, const char *str, bool *err); static bool parse_bool(const char *filename, size_t lineno, const char *str, bool *err); -static wchar_t parse_wchar(const char *filename, size_t lineno, const char *str, bool *err); +static uint32_t parse_char(const char *filename, size_t lineno, const char *str, bool *err); static struct color parse_color(const char *filename, size_t lineno, const char *str, bool *err); static uint32_t parse_uint32(const char *filename, size_t lineno, const char *str, bool *err); static int32_t parse_int32(const char *filename, size_t lineno, const char *str, bool *err); @@ -414,18 +415,11 @@ bool parse_option(struct tofi *tofi, const char *filename, size_t lineno, const tofi->window.entry.hide_input = parse_bool(filename, lineno, value, &err); } else if (strcasecmp(option, "hidden-character") == 0) { /* Unicode handling is ugly. */ - wchar_t wc = parse_wchar(filename, lineno, value, &err); - size_t buf_len = N_ELEM(tofi->window.entry.hidden_character_mb) + 1; - char *buf = xmalloc(buf_len); - size_t char_len = snprintf(buf, buf_len, "%lc", wc); - if (char_len >= buf_len) { - PARSE_ERROR(filename, lineno, "Character \"%lc\" is too large.\n", value); - err = true; - } else { - memcpy(tofi->window.entry.hidden_character_mb, buf, char_len); - tofi->window.entry.hidden_character_mb_length = char_len; + uint32_t ch = parse_char(filename, lineno, value, &err); + if (!err) { + tofi->window.entry.hidden_character_utf8_length = + utf32_to_utf8(ch, tofi->window.entry.hidden_character_utf8); } - free(buf); } else if (strcasecmp(option, "drun-launch") == 0) { tofi->drun_launch = parse_bool(filename, lineno, value, &err); } else if (strcasecmp(option, "drun-print-exec") == 0) { @@ -611,20 +605,14 @@ bool parse_bool(const char *filename, size_t lineno, const char *str, bool *err) return false; } -wchar_t parse_wchar(const char *filename, size_t lineno, const char *str, bool *err) +uint32_t parse_char(const char *filename, size_t lineno, const char *str, bool *err) { - size_t len = strlen(str); - wchar_t ch; - size_t ret = mbrtowc(&ch, str, len, NULL); - if (ret == (size_t)-2) { - return 0; - } else if (ret != len) { + char *tmp = utf8_compose(str); + uint32_t ch = utf8_to_utf32(tmp); + if (*utf8_next_char(tmp) != '\0') { PARSE_ERROR(filename, lineno, "Failed to parse \"%s\" as a character.\n", str); - if (err) { - *err = true; - } - return 0; } + free(tmp); return ch; } |