From: Timo Sirainen Date: Mon, 31 Oct 2016 17:20:51 +0000 (+0200) Subject: lib: var_expand() code cleanup - Moved short %v expansion to its own function. X-Git-Tag: 2.2.27~207 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d845c5c6d4a4b736eff6f4c5e39e84a1f2db7eee;p=thirdparty%2Fdovecot%2Fcore.git lib: var_expand() code cleanup - Moved short %v expansion to its own function. --- diff --git a/src/lib/var-expand.c b/src/lib/var-expand.c index f2da1f4e52..e0ac532b4d 100644 --- a/src/lib/var-expand.c +++ b/src/lib/var-expand.c @@ -166,6 +166,24 @@ static const struct var_expand_modifier modifiers[] = { { '\0', NULL } }; +static const char * +var_expand_short(const struct var_expand_table *table, char key) +{ + const struct var_expand_table *t; + + if (table != NULL) { + for (t = table; !TABLE_LAST(t); t++) { + if (t->key == key) + return t->value != NULL ? t->value : ""; + } + } + + /* not found */ + if (key == '%') + return "%"; + return NULL; +} + static const char * var_expand_func(const struct var_expand_func_table *func_table, const char *key, const char *data, void *context) @@ -243,7 +261,6 @@ void var_expand_with_funcs(string_t *dest, const char *str, void *context) { const struct var_expand_modifier *m; - const struct var_expand_table *t; const char *var; struct var_expand_context ctx; const char *(*modifier[MAX_MODIFIER_COUNT]) @@ -340,20 +357,8 @@ void var_expand_with_funcs(string_t *dest, const char *str, str+1, len, context); i_assert(var != NULL); str = end; - } else if (table != NULL) { - for (t = table; !TABLE_LAST(t); t++) { - if (t->key == *str) { - var = t->value != NULL ? - t->value : ""; - break; - } - } - } - - if (var == NULL) { - /* not found */ - if (*str == '%') - var = "%"; + } else { + var = var_expand_short(table, *str); } if (var != NULL) {