utils: renamed stringFoundInStringArray()

No CamelCase.  Use bool instead of int.  Make both arguments
mandatory.
This commit is contained in:
Max Kellermann 2009-11-06 19:50:47 +01:00
parent ba34d48cf0
commit f9218423b9
6 changed files with 35 additions and 30 deletions

View File

@ -60,7 +60,8 @@ archive_plugin_from_suffix(const char *suffix)
for (i=0; i < num_archive_plugins; ++i) {
const struct archive_plugin *plugin = archive_plugins[i];
if (archive_plugins_enabled[i] &&
stringFoundInStringArray(plugin->suffixes, suffix)) {
plugin->suffixes != NULL &&
string_array_contains(plugin->suffixes, suffix)) {
++i;
return plugin;
}

View File

@ -95,16 +95,6 @@ static struct config_entry config_entries[] = {
{ .name = "filter", true, true },
};
static bool
string_array_contains(const char *const* array, const char *value)
{
for (const char *const* x = array; *x; x++)
if (g_ascii_strcasecmp(*x, value) == 0)
return true;
return false;
}
static bool
get_bool(const char *value, bool *value_r)
{

View File

@ -118,8 +118,8 @@ decoder_plugin_from_suffix(const char *suffix, unsigned int next)
i = 0;
for (; i < num_decoder_plugins; ++i) {
const struct decoder_plugin *plugin = decoder_plugins[i];
if (decoder_plugins_enabled[i] &&
stringFoundInStringArray(plugin->suffixes, suffix)) {
if (decoder_plugins_enabled[i] && plugin->suffixes != NULL &&
string_array_contains(plugin->suffixes, suffix)) {
++i;
return plugin;
}
@ -140,8 +140,8 @@ decoder_plugin_from_mime_type(const char *mimeType, unsigned int next)
i = 0;
for (; i < num_decoder_plugins; ++i) {
const struct decoder_plugin *plugin = decoder_plugins[i];
if (decoder_plugins_enabled[i] &&
stringFoundInStringArray(plugin->mime_types, mimeType)) {
if (decoder_plugins_enabled[i] && plugin->mime_types != NULL &&
string_array_contains(plugin->mime_types, mimeType)) {
++i;
return plugin;
}

View File

@ -119,8 +119,8 @@ playlist_list_open_uri(const char *uri)
for (unsigned i = 0; playlist_plugins[i] != NULL; ++i) {
const struct playlist_plugin *plugin = playlist_plugins[i];
if (playlist_plugins_enabled[i] &&
stringFoundInStringArray(plugin->schemes, scheme)) {
if (playlist_plugins_enabled[i] && plugin->schemes != NULL &&
string_array_contains(plugin->schemes, scheme)) {
playlist = playlist_plugin_open_uri(plugin, uri);
if (playlist != NULL)
break;
@ -143,7 +143,8 @@ playlist_list_open_stream_mime(struct input_stream *is)
const struct playlist_plugin *plugin = playlist_plugins[i];
if (playlist_plugins_enabled[i] &&
stringFoundInStringArray(plugin->mime_types, is->mime)) {
plugin->mime_types != NULL &&
string_array_contains(plugin->mime_types, is->mime)) {
/* rewind the stream, so each plugin gets a
fresh start */
input_stream_seek(is, 0, SEEK_SET);
@ -168,8 +169,8 @@ playlist_list_open_stream_suffix(struct input_stream *is, const char *suffix)
for (unsigned i = 0; playlist_plugins[i] != NULL; ++i) {
const struct playlist_plugin *plugin = playlist_plugins[i];
if (playlist_plugins_enabled[i] &&
stringFoundInStringArray(plugin->suffixes, suffix)) {
if (playlist_plugins_enabled[i] && plugin->suffixes != NULL &&
string_array_contains(plugin->suffixes, suffix)) {
/* rewind the stream, so each plugin gets a
fresh start */
input_stream_seek(is, 0, SEEK_SET);
@ -213,8 +214,8 @@ playlist_suffix_supported(const char *suffix)
for (unsigned i = 0; playlist_plugins[i] != NULL; ++i) {
const struct playlist_plugin *plugin = playlist_plugins[i];
if (playlist_plugins_enabled[i] &&
stringFoundInStringArray(plugin->suffixes, suffix))
if (playlist_plugins_enabled[i] && plugin->suffixes != NULL &&
string_array_contains(plugin->suffixes, suffix))
return true;
}

View File

@ -132,13 +132,15 @@ int set_nonblocking(int fd)
#endif
}
int stringFoundInStringArray(const char *const*array, const char *suffix)
bool
string_array_contains(const char *const* haystack, const char *needle)
{
while (array && *array) {
if (g_ascii_strcasecmp(*array, suffix) == 0)
return 1;
array++;
}
assert(haystack != NULL);
assert(needle != NULL);
return 0;
for (; *haystack != NULL; ++haystack)
if (g_ascii_strcasecmp(*haystack, needle) == 0)
return true;
return false;
}

View File

@ -20,6 +20,8 @@
#ifndef MPD_UTILS_H
#define MPD_UTILS_H
#include <stdbool.h>
#ifndef assert_static
/* Compile time assertion developed by Ralf Holly */
/* http://pera-software.com/articles/compile-time-assertions.pdf */
@ -33,6 +35,15 @@ char *parsePath(char *path);
int set_nonblocking(int fd);
int stringFoundInStringArray(const char *const*array, const char *suffix);
/**
* Checks whether a string array contains the specified string.
*
* @param haystack a NULL terminated list of strings
* @param needle the string to search for; the comparison is
* case-insensitive for ASCII characters
* @return true if found
*/
bool
string_array_contains(const char *const* haystack, const char *needle);
#endif