mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-12 04:27:51 -05:00
config: refactor: add str_to_wchars(), use it when parsing word-delimiters
This commit is contained in:
parent
b09606e343
commit
94266b99d7
1 changed files with 24 additions and 8 deletions
32
config.c
32
config.c
|
|
@ -397,6 +397,25 @@ str_to_double(const char *s, double *res)
|
|||
return errno == 0 && *end == '\0';
|
||||
}
|
||||
|
||||
static bool
|
||||
str_to_wchars(const char *s, wchar_t **res, struct config *conf,
|
||||
const char *path, int lineno,
|
||||
const char *section, const char *key)
|
||||
{
|
||||
*res = NULL;
|
||||
|
||||
size_t chars = mbstowcs(NULL, s, 0);
|
||||
if (chars == (size_t)-1) {
|
||||
LOG_AND_NOTIFY_ERR("%s:%d: [%s]: %s: invalid string: %s",
|
||||
path, lineno, section, key, s);
|
||||
return false;
|
||||
}
|
||||
|
||||
*res = xmalloc((chars + 1) * sizeof(wchar_t));
|
||||
mbstowcs(*res, s, chars + 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
str_to_color(const char *s, uint32_t *color, bool allow_alpha,
|
||||
struct config *conf, const char *path, int lineno,
|
||||
|
|
@ -712,18 +731,15 @@ parse_section_main(const char *key, const char *value, struct config *conf,
|
|||
}
|
||||
|
||||
else if (strcmp(key, "word-delimiters") == 0) {
|
||||
size_t chars = mbstowcs(NULL, value, 0);
|
||||
if (chars == (size_t)-1) {
|
||||
LOG_AND_NOTIFY_ERR(
|
||||
"%s:%d: [default]: word-delimiters: invalid string: %s",
|
||||
path, lineno, value);
|
||||
wchar_t *word_delimiters;
|
||||
if (!str_to_wchars(value, &word_delimiters, conf, path, lineno,
|
||||
"default", "word-delimiters"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
free(conf->word_delimiters);
|
||||
conf->word_delimiters = word_delimiters;
|
||||
|
||||
conf->word_delimiters = xmalloc((chars + 1) * sizeof(wchar_t));
|
||||
mbstowcs(conf->word_delimiters, value, chars + 1);
|
||||
}
|
||||
|
||||
else if (strcmp(key, "notify") == 0) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue