utils: move string_array_contains() to string_util.c

This commit is contained in:
Max Kellermann 2010-12-23 16:13:11 +01:00
parent e3cba18532
commit 0958ed5844
9 changed files with 89 additions and 36 deletions

View File

@ -214,6 +214,7 @@ mpd_headers = \
src/strset.h \
src/uri.h \
src/utils.h \
src/string_util.h \
src/volume.h \
src/zeroconf.h src/zeroconf-internal.h \
src/locate.h \
@ -347,6 +348,7 @@ src_mpd_SOURCES = \
src/strset.c \
src/uri.c \
src/utils.c \
src/string_util.c \
src/volume.c \
src/locate.c \
src/stored_playlist.c \
@ -854,7 +856,7 @@ test_read_conf_CPPFLAGS = $(AM_CPPFLAGS) \
test_read_conf_LDADD = $(MPD_LIBS) \
$(GLIB_LIBS)
test_read_conf_SOURCES = test/read_conf.c \
src/conf.c src/tokenizer.c src/utils.c
src/conf.c src/tokenizer.c src/utils.c src/string_util.c
test_run_input_CPPFLAGS = $(AM_CPPFLAGS) \
$(ARCHIVE_CFLAGS) \
@ -864,7 +866,7 @@ test_run_input_LDADD = $(MPD_LIBS) \
$(INPUT_LIBS) \
$(GLIB_LIBS)
test_run_input_SOURCES = test/run_input.c \
src/conf.c src/tokenizer.c src/utils.c \
src/conf.c src/tokenizer.c src/utils.c src/string_util.c\
src/tag.c src/tag_pool.c src/tag_save.c \
src/fd_util.c \
$(ARCHIVE_SRC) \
@ -882,7 +884,7 @@ test_dump_playlist_LDADD = $(MPD_LIBS) \
$(INPUT_LIBS) \
$(GLIB_LIBS)
test_dump_playlist_SOURCES = test/dump_playlist.c \
src/conf.c src/tokenizer.c src/utils.c \
src/conf.c src/tokenizer.c src/utils.c src/string_util.c\
src/uri.c \
src/song.c src/tag.c src/tag_pool.c src/tag_save.c \
src/text_input_stream.c src/fifo_buffer.c \
@ -911,7 +913,7 @@ test_run_decoder_LDADD = $(MPD_LIBS) \
$(INPUT_LIBS) $(DECODER_LIBS) \
$(GLIB_LIBS)
test_run_decoder_SOURCES = test/run_decoder.c \
src/conf.c src/tokenizer.c src/utils.c src/log.c \
src/conf.c src/tokenizer.c src/utils.c src/string_util.c src/log.c \
src/tag.c src/tag_pool.c \
src/replay_gain_info.c \
src/uri.c \
@ -934,7 +936,7 @@ test_read_tags_LDADD = $(MPD_LIBS) \
$(INPUT_LIBS) $(DECODER_LIBS) \
$(GLIB_LIBS)
test_read_tags_SOURCES = test/read_tags.c \
src/conf.c src/tokenizer.c src/utils.c src/log.c \
src/conf.c src/tokenizer.c src/utils.c src/string_util.c src/log.c \
src/tag.c src/tag_pool.c \
src/replay_gain_info.c \
src/uri.c \
@ -953,7 +955,7 @@ test_run_filter_LDADD = $(MPD_LIBS) \
test_run_filter_SOURCES = test/run_filter.c \
src/filter_plugin.c \
src/filter_registry.c \
src/conf.c src/tokenizer.c src/utils.c \
src/conf.c src/tokenizer.c src/utils.c src/string_util.c \
src/pcm_volume.c src/pcm_convert.c src/pcm_byteswap.c \
src/pcm_format.c src/pcm_channels.c src/pcm_dither.c \
src/pcm_pack.c \
@ -974,7 +976,7 @@ if ENABLE_ENCODER
noinst_PROGRAMS += test/run_encoder
test_run_encoder_SOURCES = test/run_encoder.c \
src/conf.c src/tokenizer.c \
src/utils.c \
src/utils.c src/string_util.c \
src/tag.c src/tag_pool.c \
src/audio_check.c \
src/audio_format.c \
@ -1030,7 +1032,7 @@ test_run_output_LDADD = $(MPD_LIBS) \
$(OUTPUT_LIBS) \
$(GLIB_LIBS)
test_run_output_SOURCES = test/run_output.c \
src/conf.c src/tokenizer.c src/utils.c src/log.c \
src/conf.c src/tokenizer.c src/utils.c src/string_util.c src/log.c \
src/audio_check.c \
src/audio_format.c \
src/audio_parser.c \
@ -1066,7 +1068,7 @@ test_read_mixer_LDADD = $(MPD_LIBS) \
$(OUTPUT_LIBS) \
$(GLIB_LIBS)
test_read_mixer_SOURCES = test/read_mixer.c \
src/conf.c src/tokenizer.c src/utils.c src/log.c \
src/conf.c src/tokenizer.c src/utils.c src/string_util.c src/log.c \
src/mixer_control.c src/mixer_api.c \
src/filter_plugin.c \
src/filter/volume_filter_plugin.c \

View File

@ -20,7 +20,7 @@
#include "config.h"
#include "archive_list.h"
#include "archive_plugin.h"
#include "utils.h"
#include "string_util.h"
#include "archive/bz2_archive_plugin.h"
#include "archive/iso9660_archive_plugin.h"
#include "archive/zzip_archive_plugin.h"

View File

@ -20,6 +20,7 @@
#include "config.h"
#include "conf.h"
#include "utils.h"
#include "string_util.h"
#include "tokenizer.h"
#include "path.h"
#include "glib_compat.h"

View File

@ -19,7 +19,7 @@
#include "config.h"
#include "decoder_plugin.h"
#include "utils.h"
#include "string_util.h"
#include <assert.h>

View File

@ -31,7 +31,7 @@
#include "playlist/flac_playlist_plugin.h"
#include "input_stream.h"
#include "uri.h"
#include "utils.h"
#include "string_util.h"
#include "conf.h"
#include "glib_compat.h"
#include "mpd_error.h"

38
src/string_util.c Normal file
View File

@ -0,0 +1,38 @@
/*
* Copyright (C) 2003-2010 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "config.h"
#include "string_util.h"
#include <glib.h>
#include <assert.h>
bool
string_array_contains(const char *const* haystack, const char *needle)
{
assert(haystack != NULL);
assert(needle != NULL);
for (; *haystack != NULL; ++haystack)
if (g_ascii_strcasecmp(*haystack, needle) == 0)
return true;
return false;
}

36
src/string_util.h Normal file
View File

@ -0,0 +1,36 @@
/*
* Copyright (C) 2003-2010 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPD_STRING_UTIL_H
#define MPD_STRING_UTIL_H
#include <stdbool.h>
/**
* 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

View File

@ -101,16 +101,3 @@ char *parsePath(char *path)
}
#endif
}
bool
string_array_contains(const char *const* haystack, const char *needle)
{
assert(haystack != NULL);
assert(needle != NULL);
for (; *haystack != NULL; ++haystack)
if (g_ascii_strcasecmp(*haystack, needle) == 0)
return true;
return false;
}

View File

@ -33,15 +33,4 @@
char *parsePath(char *path);
/**
* 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