From 2352cef6d0757a4d31a18561a09a10f031388e12 Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Sun, 13 Mar 2022 14:31:02 -0400 Subject: replace more strcmp if then trees with string_option() 1 Change-Id: Ic89bbb2ab41068d09c7bd9caa5ba7f38749b9084 --- lib/rbcodec/metadata/metadata_common.c | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) (limited to 'lib/rbcodec/metadata/metadata_common.c') diff --git a/lib/rbcodec/metadata/metadata_common.c b/lib/rbcodec/metadata/metadata_common.c index 202da49522..59c2f01840 100644 --- a/lib/rbcodec/metadata/metadata_common.c +++ b/lib/rbcodec/metadata/metadata_common.c @@ -260,32 +260,16 @@ bool skip_id3v2(int fd, struct mp3entry *id3) */ int string_option(const char *option, const char *const oplist[], bool ignore_case) { - int i; - int ifound = -1; const char *op; - if (ignore_case) + int (*cmp_fn)(const char*, const char*) = &strcasecmp; + if (!ignore_case) + cmp_fn = strcmp; + for (int i=0; (op=oplist[i]) != NULL; i++) { - for (i=0; (op=oplist[i]) != NULL; i++) - { - if (strcasecmp(op, option) == 0) - { - ifound = i; - break; - } - } - } - else - { - for (i=0; (op=oplist[i]) != NULL; i++) - { - if (strcmp(op, option) == 0) - { - ifound = i; - break; - } - } + if (cmp_fn(op, option) == 0) + return i; } - return ifound; + return -1; } #endif /* Parse the tag (the name-value pair) and fill id3 and buffer accordingly. -- cgit v1.2.3