]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: var_expand() code cleanup - Moved short %v expansion to its own function.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 31 Oct 2016 17:20:51 +0000 (19:20 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 9 Nov 2016 12:34:56 +0000 (14:34 +0200)
src/lib/var-expand.c

index f2da1f4e52577e33da9acc86516b9063a6e33ed6..e0ac532b4d9921dfd5a21749b53e68307c063efb 100644 (file)
@@ -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) {