string-table: use string_table_lookup() in our own macros everywhere

This commit is contained in:
Lennart Poettering 2019-03-22 12:12:29 +01:00
parent 8238423095
commit 63c691c648

View file

@ -59,12 +59,12 @@ ssize_t string_table_lookup(const char * const *table, size_t len, const char *k
#define _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_FALLBACK(name,type,max,scope) \ #define _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_FALLBACK(name,type,max,scope) \
scope type name##_from_string(const char *s) { \ scope type name##_from_string(const char *s) { \
type i; \
unsigned u = 0; \ unsigned u = 0; \
type i; \
if (!s) \ if (!s) \
return (type) -1; \ return (type) -1; \
for (i = 0; i < (type) ELEMENTSOF(name##_table); i++) \ i = (type) string_table_lookup(name##_table, ELEMENTSOF(name##_table), s); \
if (streq_ptr(name##_table[i], s)) \ if (i >= 0) \
return i; \ return i; \
if (safe_atou(s, &u) >= 0 && u <= max) \ if (safe_atou(s, &u) >= 0 && u <= max) \
return (type) u; \ return (type) u; \