diff options
author | Max Kellermann <max@duempel.org> | 2015-11-11 15:34:36 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2015-11-11 15:34:36 +0100 |
commit | 738583e3d4cd7a35aec545448f86a8c097768785 (patch) | |
tree | 67e0ed29ea1aa6c44ccaa7de1b5297715bc06f43 /src/queue | |
parent | c513478c31c8543309da5f04bb472ea6e4969603 (diff) | |
download | mpd-738583e3d4cd7a35aec545448f86a8c097768785.tar.gz mpd-738583e3d4cd7a35aec545448f86a8c097768785.tar.xz mpd-738583e3d4cd7a35aec545448f86a8c097768785.zip |
StateFile: use StringAfterPrefix() instead of StringStartsWith()
Diffstat (limited to '')
-rw-r--r-- | src/queue/PlaylistState.cxx | 53 | ||||
-rw-r--r-- | src/queue/QueueSave.cxx | 9 |
2 files changed, 26 insertions, 36 deletions
diff --git a/src/queue/PlaylistState.cxx b/src/queue/PlaylistState.cxx index 99d1b26cd..a1939e13a 100644 --- a/src/queue/PlaylistState.cxx +++ b/src/queue/PlaylistState.cxx @@ -33,6 +33,7 @@ #include "config/ConfigGlobal.hxx" #include "config/ConfigOption.hxx" #include "util/CharUtil.hxx" +#include "util/StringAPI.hxx" #include "util/StringCompare.hxx" #include "Log.hxx" @@ -132,11 +133,10 @@ playlist_state_restore(const char *line, TextFile &file, SongTime seek_time = SongTime::zero(); bool random_mode = false; - if (!StringStartsWith(line, PLAYLIST_STATE_FILE_STATE)) + line = StringAfterPrefix(line, PLAYLIST_STATE_FILE_STATE); + if (line == nullptr) return false; - line += sizeof(PLAYLIST_STATE_FILE_STATE) - 1; - PlayerState state; if (strcmp(line, PLAYLIST_STATE_FILE_STATE_PLAY) == 0) state = PlayerState::PLAY; @@ -146,39 +146,28 @@ playlist_state_restore(const char *line, TextFile &file, state = PlayerState::STOP; while ((line = file.ReadLine()) != nullptr) { - if (StringStartsWith(line, PLAYLIST_STATE_FILE_TIME)) { - double seconds = atof(line + strlen(PLAYLIST_STATE_FILE_TIME)); - seek_time = SongTime::FromS(seconds); - } else if (StringStartsWith(line, PLAYLIST_STATE_FILE_REPEAT)) { - playlist.SetRepeat(pc, - strcmp(&(line[strlen(PLAYLIST_STATE_FILE_REPEAT)]), - "1") == 0); - } else if (StringStartsWith(line, PLAYLIST_STATE_FILE_SINGLE)) { - playlist.SetSingle(pc, - strcmp(&(line[strlen(PLAYLIST_STATE_FILE_SINGLE)]), - "1") == 0); - } else if (StringStartsWith(line, PLAYLIST_STATE_FILE_CONSUME)) { - playlist.SetConsume(strcmp(&(line[strlen(PLAYLIST_STATE_FILE_CONSUME)]), - "1") == 0); - } else if (StringStartsWith(line, PLAYLIST_STATE_FILE_CROSSFADE)) { - pc.SetCrossFade(atoi(line + strlen(PLAYLIST_STATE_FILE_CROSSFADE))); - } else if (StringStartsWith(line, PLAYLIST_STATE_FILE_MIXRAMPDB)) { - pc.SetMixRampDb(atof(line + strlen(PLAYLIST_STATE_FILE_MIXRAMPDB))); - } else if (StringStartsWith(line, PLAYLIST_STATE_FILE_MIXRAMPDELAY)) { - const char *p = line + strlen(PLAYLIST_STATE_FILE_MIXRAMPDELAY); - + const char *p; + if ((p = StringAfterPrefix(line, PLAYLIST_STATE_FILE_TIME))) { + seek_time = SongTime::FromS(atof(p)); + } else if ((p = StringAfterPrefix(line, PLAYLIST_STATE_FILE_REPEAT))) { + playlist.SetRepeat(pc, StringIsEqual(p, "1")); + } else if ((p = StringAfterPrefix(line, PLAYLIST_STATE_FILE_SINGLE))) { + playlist.SetSingle(pc, StringIsEqual(p, "1")); + } else if ((p = StringAfterPrefix(line, PLAYLIST_STATE_FILE_CONSUME))) { + playlist.SetConsume(StringIsEqual(p, "1")); + } else if ((p = StringAfterPrefix(line, PLAYLIST_STATE_FILE_CROSSFADE))) { + pc.SetCrossFade(atoi(p)); + } else if ((p = StringAfterPrefix(line, PLAYLIST_STATE_FILE_MIXRAMPDB))) { + pc.SetMixRampDb(atof(p)); + } else if ((p = StringAfterPrefix(line, 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 (StringStartsWith(line, PLAYLIST_STATE_FILE_RANDOM)) { - random_mode = - strcmp(line + strlen(PLAYLIST_STATE_FILE_RANDOM), - "1") == 0; - } else if (StringStartsWith(line, PLAYLIST_STATE_FILE_CURRENT)) { - current = atoi(&(line - [strlen - (PLAYLIST_STATE_FILE_CURRENT)])); + } else if ((p = StringAfterPrefix(line, PLAYLIST_STATE_FILE_RANDOM))) { + random_mode = StringIsEqual(p, "1"); + } else if ((p = StringAfterPrefix(line, PLAYLIST_STATE_FILE_CURRENT))) { + current = atoi(p); } else if (StringStartsWith(line, PLAYLIST_STATE_FILE_PLAYLIST_BEGIN)) { playlist_state_load(file, song_loader, playlist); diff --git a/src/queue/QueueSave.cxx b/src/queue/QueueSave.cxx index cb8611cf8..3b9589450 100644 --- a/src/queue/QueueSave.cxx +++ b/src/queue/QueueSave.cxx @@ -83,8 +83,9 @@ queue_load_song(TextFile &file, const SongLoader &loader, return; uint8_t priority = 0; - if (StringStartsWith(line, PRIO_LABEL)) { - priority = strtoul(line + sizeof(PRIO_LABEL) - 1, nullptr, 10); + const char *p; + if ((p = StringAfterPrefix(line, PRIO_LABEL))) { + priority = strtoul(p, nullptr, 10); line = file.ReadLine(); if (line == nullptr) @@ -93,8 +94,8 @@ queue_load_song(TextFile &file, const SongLoader &loader, DetachedSong *song; - if (StringStartsWith(line, SONG_BEGIN)) { - const char *uri = line + sizeof(SONG_BEGIN) - 1; + if ((p = StringAfterPrefix(line, PRIO_LABEL))) { + const char *uri = p; Error error; song = song_load(file, uri, error); |