aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/DatabaseSave.cxx9
-rw-r--r--src/DirectorySave.cxx13
-rw-r--r--src/OutputState.cxx5
-rw-r--r--src/PlaylistState.cxx27
-rw-r--r--src/QueueSave.cxx7
-rw-r--r--src/Volume.cxx5
-rw-r--r--src/decoder/MadDecoderPlugin.cxx3
-rw-r--r--src/input/CdioParanoiaInputPlugin.cxx3
-rw-r--r--src/input/DespotifyInputPlugin.cxx5
-rw-r--r--src/input/FfmpegInputPlugin.cxx15
-rw-r--r--src/input/MmsInputPlugin.cxx10
-rw-r--r--src/ls.cxx5
-rw-r--r--src/playlist/ExtM3uPlaylistPlugin.cxx4
-rw-r--r--src/playlist/SoundCloudPlaylistPlugin.cxx5
-rw-r--r--src/util/StringUtil.cxx8
-rw-r--r--src/util/StringUtil.hxx4
16 files changed, 68 insertions, 60 deletions
diff --git a/src/DatabaseSave.cxx b/src/DatabaseSave.cxx
index 73de3b951..a9ec281ce 100644
--- a/src/DatabaseSave.cxx
+++ b/src/DatabaseSave.cxx
@@ -27,6 +27,7 @@
#include "tag/Tag.hxx"
#include "tag/TagSettings.h"
#include "fs/Charset.hxx"
+#include "util/StringUtil.hxx"
#include "util/Error.hxx"
#include "Log.hxx"
@@ -81,16 +82,16 @@ db_load_internal(TextFile &file, Directory &music_root, Error &error)
while ((line = file.ReadLine()) != nullptr &&
strcmp(line, DIRECTORY_INFO_END) != 0) {
- if (g_str_has_prefix(line, DB_FORMAT_PREFIX)) {
+ if (StringStartsWith(line, DB_FORMAT_PREFIX)) {
format = atoi(line + sizeof(DB_FORMAT_PREFIX) - 1);
- } else if (g_str_has_prefix(line, DIRECTORY_MPD_VERSION)) {
+ } else if (StringStartsWith(line, DIRECTORY_MPD_VERSION)) {
if (found_version) {
error.Set(db_domain, "Duplicate version line");
return false;
}
found_version = true;
- } else if (g_str_has_prefix(line, DIRECTORY_FS_CHARSET)) {
+ } else if (StringStartsWith(line, DIRECTORY_FS_CHARSET)) {
const char *new_charset;
if (found_charset) {
@@ -111,7 +112,7 @@ db_load_internal(TextFile &file, Directory &music_root, Error &error)
new_charset, old_charset);
return false;
}
- } else if (g_str_has_prefix(line, DB_TAG_PREFIX)) {
+ } else if (StringStartsWith(line, DB_TAG_PREFIX)) {
const char *name = line + sizeof(DB_TAG_PREFIX) - 1;
TagType tag = tag_name_parse(name);
if (tag == TAG_NUM_OF_ITEM_TYPES) {
diff --git a/src/DirectorySave.cxx b/src/DirectorySave.cxx
index 5e0cec8a9..6da961926 100644
--- a/src/DirectorySave.cxx
+++ b/src/DirectorySave.cxx
@@ -24,6 +24,7 @@
#include "SongSave.hxx"
#include "PlaylistDatabase.hxx"
#include "TextFile.hxx"
+#include "util/StringUtil.hxx"
#include "util/NumberParser.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
@@ -88,7 +89,7 @@ directory_load_subdir(TextFile &file, Directory &parent, const char *name,
return nullptr;
}
- if (g_str_has_prefix(line, DIRECTORY_MTIME)) {
+ if (StringStartsWith(line, DIRECTORY_MTIME)) {
directory->mtime =
ParseUint64(line + sizeof(DIRECTORY_MTIME) - 1);
@@ -100,7 +101,7 @@ directory_load_subdir(TextFile &file, Directory &parent, const char *name,
}
}
- if (!g_str_has_prefix(line, DIRECTORY_BEGIN)) {
+ if (!StringStartsWith(line, DIRECTORY_BEGIN)) {
error.Format(directory_domain, "Malformed line: %s", line);
directory->Delete();
return nullptr;
@@ -121,15 +122,15 @@ directory_load(TextFile &file, Directory &directory, Error &error)
const char *line;
while ((line = file.ReadLine()) != nullptr &&
- !g_str_has_prefix(line, DIRECTORY_END)) {
- if (g_str_has_prefix(line, DIRECTORY_DIR)) {
+ !StringStartsWith(line, DIRECTORY_END)) {
+ if (StringStartsWith(line, DIRECTORY_DIR)) {
Directory *subdir =
directory_load_subdir(file, directory,
line + sizeof(DIRECTORY_DIR) - 1,
error);
if (subdir == nullptr)
return false;
- } else if (g_str_has_prefix(line, SONG_BEGIN)) {
+ } else if (StringStartsWith(line, SONG_BEGIN)) {
const char *name = line + sizeof(SONG_BEGIN) - 1;
Song *song;
@@ -144,7 +145,7 @@ directory_load(TextFile &file, Directory &directory, Error &error)
return false;
directory.AddSong(song);
- } else if (g_str_has_prefix(line, PLAYLIST_META_BEGIN)) {
+ } else if (StringStartsWith(line, PLAYLIST_META_BEGIN)) {
/* duplicate the name, because
playlist_metadata_load() will overwrite the
buffer */
diff --git a/src/OutputState.cxx b/src/OutputState.cxx
index 8705176ae..0124e1e33 100644
--- a/src/OutputState.cxx
+++ b/src/OutputState.cxx
@@ -28,8 +28,7 @@
#include "OutputInternal.hxx"
#include "OutputError.hxx"
#include "Log.hxx"
-
-#include <glib.h>
+#include "util/StringUtil.hxx"
#include <assert.h>
#include <stdlib.h>
@@ -61,7 +60,7 @@ audio_output_state_read(const char *line)
const char *name;
struct audio_output *ao;
- if (!g_str_has_prefix(line, AUDIO_DEVICE_STATE))
+ if (!StringStartsWith(line, AUDIO_DEVICE_STATE))
return false;
line += sizeof(AUDIO_DEVICE_STATE) - 1;
diff --git a/src/PlaylistState.cxx b/src/PlaylistState.cxx
index ac2deebbf..83f4b1143 100644
--- a/src/PlaylistState.cxx
+++ b/src/PlaylistState.cxx
@@ -33,10 +33,9 @@
#include "ConfigOption.hxx"
#include "fs/Limits.hxx"
#include "util/CharUtil.hxx"
+#include "util/StringUtil.hxx"
#include "Log.hxx"
-#include <glib.h>
-
#include <string.h>
#include <stdlib.h>
@@ -112,7 +111,7 @@ playlist_state_load(TextFile &file, struct playlist &playlist)
return;
}
- while (!g_str_has_prefix(line, PLAYLIST_STATE_FILE_PLAYLIST_END)) {
+ while (!StringStartsWith(line, PLAYLIST_STATE_FILE_PLAYLIST_END)) {
queue_load_song(file, line, playlist.queue);
line = file.ReadLine();
@@ -135,7 +134,7 @@ playlist_state_restore(const char *line, TextFile &file,
int seek_time = 0;
bool random_mode = false;
- if (!g_str_has_prefix(line, PLAYLIST_STATE_FILE_STATE))
+ if (!StringStartsWith(line, PLAYLIST_STATE_FILE_STATE))
return false;
line += sizeof(PLAYLIST_STATE_FILE_STATE) - 1;
@@ -149,40 +148,40 @@ playlist_state_restore(const char *line, TextFile &file,
state = PlayerState::STOP;
while ((line = file.ReadLine()) != nullptr) {
- if (g_str_has_prefix(line, PLAYLIST_STATE_FILE_TIME)) {
+ if (StringStartsWith(line, PLAYLIST_STATE_FILE_TIME)) {
seek_time =
atoi(&(line[strlen(PLAYLIST_STATE_FILE_TIME)]));
- } else if (g_str_has_prefix(line, PLAYLIST_STATE_FILE_REPEAT)) {
+ } else if (StringStartsWith(line, PLAYLIST_STATE_FILE_REPEAT)) {
playlist.SetRepeat(pc,
strcmp(&(line[strlen(PLAYLIST_STATE_FILE_REPEAT)]),
"1") == 0);
- } else if (g_str_has_prefix(line, PLAYLIST_STATE_FILE_SINGLE)) {
+ } else if (StringStartsWith(line, PLAYLIST_STATE_FILE_SINGLE)) {
playlist.SetSingle(pc,
strcmp(&(line[strlen(PLAYLIST_STATE_FILE_SINGLE)]),
"1") == 0);
- } else if (g_str_has_prefix(line, PLAYLIST_STATE_FILE_CONSUME)) {
+ } else if (StringStartsWith(line, PLAYLIST_STATE_FILE_CONSUME)) {
playlist.SetConsume(strcmp(&(line[strlen(PLAYLIST_STATE_FILE_CONSUME)]),
"1") == 0);
- } else if (g_str_has_prefix(line, PLAYLIST_STATE_FILE_CROSSFADE)) {
+ } else if (StringStartsWith(line, PLAYLIST_STATE_FILE_CROSSFADE)) {
pc.SetCrossFade(atoi(line + strlen(PLAYLIST_STATE_FILE_CROSSFADE)));
- } else if (g_str_has_prefix(line, PLAYLIST_STATE_FILE_MIXRAMPDB)) {
+ } else if (StringStartsWith(line, PLAYLIST_STATE_FILE_MIXRAMPDB)) {
pc.SetMixRampDb(atof(line + strlen(PLAYLIST_STATE_FILE_MIXRAMPDB)));
- } else if (g_str_has_prefix(line, PLAYLIST_STATE_FILE_MIXRAMPDELAY)) {
+ } else if (StringStartsWith(line, PLAYLIST_STATE_FILE_MIXRAMPDELAY)) {
const char *p = line + strlen(PLAYLIST_STATE_FILE_MIXRAMPDELAY);
/* this check discards "nan" which was used
prior to MPD 0.18 */
if (IsDigitASCII(*p))
pc.SetMixRampDelay(atof(p));
- } else if (g_str_has_prefix(line, PLAYLIST_STATE_FILE_RANDOM)) {
+ } else if (StringStartsWith(line, PLAYLIST_STATE_FILE_RANDOM)) {
random_mode =
strcmp(line + strlen(PLAYLIST_STATE_FILE_RANDOM),
"1") == 0;
- } else if (g_str_has_prefix(line, PLAYLIST_STATE_FILE_CURRENT)) {
+ } else if (StringStartsWith(line, PLAYLIST_STATE_FILE_CURRENT)) {
current = atoi(&(line
[strlen
(PLAYLIST_STATE_FILE_CURRENT)]));
- } else if (g_str_has_prefix(line,
+ } else if (StringStartsWith(line,
PLAYLIST_STATE_FILE_PLAYLIST_BEGIN)) {
playlist_state_load(file, playlist);
}
diff --git a/src/QueueSave.cxx b/src/QueueSave.cxx
index 6a1a51992..af834090b 100644
--- a/src/QueueSave.cxx
+++ b/src/QueueSave.cxx
@@ -26,13 +26,12 @@
#include "DatabasePlugin.hxx"
#include "DatabaseGlue.hxx"
#include "TextFile.hxx"
+#include "util/StringUtil.hxx"
#include "util/UriUtil.hxx"
#include "util/Error.hxx"
#include "fs/Traits.hxx"
#include "Log.hxx"
-#include <glib.h>
-
#include <stdlib.h>
#define PRIO_LABEL "Prio: "
@@ -78,7 +77,7 @@ queue_load_song(TextFile &file, const char *line, queue &queue)
return;
uint8_t priority = 0;
- if (g_str_has_prefix(line, PRIO_LABEL)) {
+ if (StringStartsWith(line, PRIO_LABEL)) {
priority = strtoul(line + sizeof(PRIO_LABEL) - 1, nullptr, 10);
line = file.ReadLine();
@@ -89,7 +88,7 @@ queue_load_song(TextFile &file, const char *line, queue &queue)
const Database *db = nullptr;
Song *song;
- if (g_str_has_prefix(line, SONG_BEGIN)) {
+ if (StringStartsWith(line, SONG_BEGIN)) {
const char *uri = line + sizeof(SONG_BEGIN) - 1;
if (!uri_has_scheme(uri) && !PathTraits::IsAbsoluteUTF8(uri))
return;
diff --git a/src/Volume.cxx b/src/Volume.cxx
index 3f7210f6c..a4112a4cc 100644
--- a/src/Volume.cxx
+++ b/src/Volume.cxx
@@ -22,12 +22,11 @@
#include "MixerAll.hxx"
#include "Idle.hxx"
#include "GlobalEvents.hxx"
+#include "util/StringUtil.hxx"
#include "util/Domain.hxx"
#include "system/PeriodClock.hxx"
#include "Log.hxx"
-#include <glib.h>
-
#include <assert.h>
#include <stdlib.h>
@@ -106,7 +105,7 @@ read_sw_volume_state(const char *line)
char *end = nullptr;
long int sv;
- if (!g_str_has_prefix(line, SW_VOLUME_STATE))
+ if (!StringStartsWith(line, SW_VOLUME_STATE))
return false;
line += sizeof(SW_VOLUME_STATE) - 1;
diff --git a/src/decoder/MadDecoderPlugin.cxx b/src/decoder/MadDecoderPlugin.cxx
index 4dfb752f0..0359840fc 100644
--- a/src/decoder/MadDecoderPlugin.cxx
+++ b/src/decoder/MadDecoderPlugin.cxx
@@ -26,6 +26,7 @@
#include "tag/TagRva2.hxx"
#include "tag/TagHandler.hxx"
#include "CheckAudioFormat.hxx"
+#include "util/StringUtil.hxx"
#include "util/ASCII.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
@@ -689,7 +690,7 @@ parse_lame(struct lame *lame, struct mad_bitptr *ptr, int *bitlen)
/* This is technically incorrect, since the encoder might not be lame.
* But there's no other way to determine if this is a lame tag, and we
* wouldn't want to go reading a tag that's not there. */
- if (!g_str_has_prefix(lame->encoder, "LAME"))
+ if (!StringStartsWith(lame->encoder, "LAME"))
return false;
if (sscanf(lame->encoder+4, "%u.%u",
diff --git a/src/input/CdioParanoiaInputPlugin.cxx b/src/input/CdioParanoiaInputPlugin.cxx
index cc366bff5..de699ea3a 100644
--- a/src/input/CdioParanoiaInputPlugin.cxx
+++ b/src/input/CdioParanoiaInputPlugin.cxx
@@ -25,6 +25,7 @@
#include "CdioParanoiaInputPlugin.hxx"
#include "InputStream.hxx"
#include "InputPlugin.hxx"
+#include "util/StringUtil.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "system/ByteOrder.hxx"
@@ -117,7 +118,7 @@ struct cdio_uri {
static bool
parse_cdio_uri(struct cdio_uri *dest, const char *src, Error &error)
{
- if (!g_str_has_prefix(src, "cdda://"))
+ if (!StringStartsWith(src, "cdda://"))
return false;
src += 7;
diff --git a/src/input/DespotifyInputPlugin.cxx b/src/input/DespotifyInputPlugin.cxx
index b08299516..9441ef327 100644
--- a/src/input/DespotifyInputPlugin.cxx
+++ b/src/input/DespotifyInputPlugin.cxx
@@ -23,14 +23,13 @@
#include "InputStream.hxx"
#include "InputPlugin.hxx"
#include "tag/Tag.hxx"
+#include "util/StringUtil.hxx"
#include "Log.hxx"
extern "C" {
#include <despotify.h>
}
-#include <glib.h>
-
#include <unistd.h>
#include <string.h>
#include <errno.h>
@@ -130,7 +129,7 @@ input_despotify_open(const char *url,
struct ds_link *ds_link;
struct ds_track *track;
- if (!g_str_has_prefix(url, "spt://"))
+ if (!StringStartsWith(url, "spt://"))
return nullptr;
session = mpd_despotify_get_session();
diff --git a/src/input/FfmpegInputPlugin.cxx b/src/input/FfmpegInputPlugin.cxx
index c6f4afb7f..7d041677b 100644
--- a/src/input/FfmpegInputPlugin.cxx
+++ b/src/input/FfmpegInputPlugin.cxx
@@ -24,6 +24,7 @@
#include "FfmpegInputPlugin.hxx"
#include "InputStream.hxx"
#include "InputPlugin.hxx"
+#include "util/StringUtil.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
@@ -32,8 +33,6 @@ extern "C" {
#include <libavformat/avformat.h>
}
-#include <glib.h>
-
struct FfmpegInputStream {
InputStream base;
@@ -90,12 +89,12 @@ input_ffmpeg_open(const char *uri,
Mutex &mutex, Cond &cond,
Error &error)
{
- if (!g_str_has_prefix(uri, "gopher://") &&
- !g_str_has_prefix(uri, "rtp://") &&
- !g_str_has_prefix(uri, "rtsp://") &&
- !g_str_has_prefix(uri, "rtmp://") &&
- !g_str_has_prefix(uri, "rtmpt://") &&
- !g_str_has_prefix(uri, "rtmps://"))
+ if (!StringStartsWith(uri, "gopher://") &&
+ !StringStartsWith(uri, "rtp://") &&
+ !StringStartsWith(uri, "rtsp://") &&
+ !StringStartsWith(uri, "rtmp://") &&
+ !StringStartsWith(uri, "rtmpt://") &&
+ !StringStartsWith(uri, "rtmps://"))
return nullptr;
AVIOContext *h;
diff --git a/src/input/MmsInputPlugin.cxx b/src/input/MmsInputPlugin.cxx
index df45f71e8..2c7f6d166 100644
--- a/src/input/MmsInputPlugin.cxx
+++ b/src/input/MmsInputPlugin.cxx
@@ -21,10 +21,10 @@
#include "MmsInputPlugin.hxx"
#include "InputStream.hxx"
#include "InputPlugin.hxx"
+#include "util/StringUtil.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
-#include <glib.h>
#include <libmms/mmsx.h>
struct MmsInputStream {
@@ -58,10 +58,10 @@ input_mms_open(const char *url,
Mutex &mutex, Cond &cond,
Error &error)
{
- if (!g_str_has_prefix(url, "mms://") &&
- !g_str_has_prefix(url, "mmsh://") &&
- !g_str_has_prefix(url, "mmst://") &&
- !g_str_has_prefix(url, "mmsu://"))
+ if (!StringStartsWith(url, "mms://") &&
+ !StringStartsWith(url, "mmsh://") &&
+ !StringStartsWith(url, "mmst://") &&
+ !StringStartsWith(url, "mmsu://"))
return nullptr;
const auto mms = mmsx_connect(nullptr, nullptr, url, 128 * 1024);
diff --git a/src/ls.cxx b/src/ls.cxx
index ec8ce6fbe..117c8875b 100644
--- a/src/ls.cxx
+++ b/src/ls.cxx
@@ -19,11 +19,10 @@
#include "config.h"
#include "ls.hxx"
+#include "util/StringUtil.hxx"
#include "util/UriUtil.hxx"
#include "Client.hxx"
-#include <glib.h>
-
#include <assert.h>
/**
@@ -90,7 +89,7 @@ bool uri_supported_scheme(const char *uri)
assert(uri_has_scheme(uri));
while (*urlPrefixes) {
- if (g_str_has_prefix(uri, *urlPrefixes))
+ if (StringStartsWith(uri, *urlPrefixes))
return true;
urlPrefixes++;
}
diff --git a/src/playlist/ExtM3uPlaylistPlugin.cxx b/src/playlist/ExtM3uPlaylistPlugin.cxx
index 8d260fec7..a9c22a933 100644
--- a/src/playlist/ExtM3uPlaylistPlugin.cxx
+++ b/src/playlist/ExtM3uPlaylistPlugin.cxx
@@ -26,8 +26,6 @@
#include "util/StringUtil.hxx"
#include "TextInputStream.hxx"
-#include <glib.h>
-
#include <string.h>
#include <stdlib.h>
@@ -119,7 +117,7 @@ ExtM3uPlaylist::NextSong()
line_s = line.c_str();
- if (g_str_has_prefix(line_s, "#EXTINF:")) {
+ if (StringStartsWith(line_s, "#EXTINF:")) {
delete tag;
tag = extm3u_parse_tag(line_s + 8);
continue;
diff --git a/src/playlist/SoundCloudPlaylistPlugin.cxx b/src/playlist/SoundCloudPlaylistPlugin.cxx
index f6797b14d..0d4b39948 100644
--- a/src/playlist/SoundCloudPlaylistPlugin.cxx
+++ b/src/playlist/SoundCloudPlaylistPlugin.cxx
@@ -25,6 +25,7 @@
#include "InputStream.hxx"
#include "Song.hxx"
#include "tag/Tag.hxx"
+#include "util/StringUtil.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
@@ -65,9 +66,9 @@ static char *
soundcloud_resolve(const char* uri) {
char *u, *ru;
- if (g_str_has_prefix(uri, "http://")) {
+ if (StringStartsWith(uri, "http://")) {
u = g_strdup(uri);
- } else if (g_str_has_prefix(uri, "soundcloud.com")) {
+ } else if (StringStartsWith(uri, "soundcloud.com")) {
u = g_strconcat("http://", uri, nullptr);
} else {
/* assume it's just a path on soundcloud.com */
diff --git a/src/util/StringUtil.cxx b/src/util/StringUtil.cxx
index 7e295bf90..512a75f5c 100644
--- a/src/util/StringUtil.cxx
+++ b/src/util/StringUtil.cxx
@@ -22,6 +22,7 @@
#include "ASCII.hxx"
#include <assert.h>
+#include <string.h>
const char *
strchug_fast(const char *p)
@@ -33,6 +34,13 @@ strchug_fast(const char *p)
}
bool
+StringStartsWith(const char *haystack, const char *needle)
+{
+ const size_t length = strlen(needle);
+ return memcmp(haystack, needle, length) == 0;
+}
+
+bool
string_array_contains(const char *const* haystack, const char *needle)
{
assert(haystack != nullptr);
diff --git a/src/util/StringUtil.hxx b/src/util/StringUtil.hxx
index 1c67910a9..f25160107 100644
--- a/src/util/StringUtil.hxx
+++ b/src/util/StringUtil.hxx
@@ -40,6 +40,10 @@ strchug_fast(char *p)
return const_cast<char *>(strchug_fast((const char *)p));
}
+gcc_pure
+bool
+StringStartsWith(const char *haystack, const char *needle);
+
/**
* Checks whether a string array contains the specified string.
*