SongSave, queue/PlaylistState, tag/ReplayGain: use portable atof() wrappers

For Android pre-5.0 compatibility (#213).
This commit is contained in:
Max Kellermann 2018-02-09 20:46:55 +01:00
parent 0f8d223c7f
commit e8b70dbca4
3 changed files with 11 additions and 8 deletions

View File

@ -28,6 +28,7 @@
#include "tag/TagBuilder.hxx"
#include "util/StringUtil.hxx"
#include "util/RuntimeError.hxx"
#include "util/NumberParser.hxx"
#include <string.h>
#include <stdlib.h>
@ -94,7 +95,7 @@ song_load(TextFile &file, const char *uri)
if ((type = tag_name_parse(line)) != TAG_NUM_OF_ITEM_TYPES) {
tag.AddItem(type, value);
} else if (strcmp(line, "Time") == 0) {
tag.SetDuration(SignedSongTime::FromS(atof(value)));
tag.SetDuration(SignedSongTime::FromS(ParseDouble(value)));
} else if (strcmp(line, "Playlist") == 0) {
tag.SetHasPlaylist(strcmp(value, "yes") == 0);
} else if (strcmp(line, SONG_MTIME) == 0) {

View File

@ -35,6 +35,7 @@
#include "util/CharUtil.hxx"
#include "util/StringAPI.hxx"
#include "util/StringCompare.hxx"
#include "util/NumberParser.hxx"
#include "Log.hxx"
#include <string.h>
@ -148,7 +149,7 @@ playlist_state_restore(const char *line, TextFile &file,
while ((line = file.ReadLine()) != nullptr) {
const char *p;
if ((p = StringAfterPrefix(line, PLAYLIST_STATE_FILE_TIME))) {
seek_time = SongTime::FromS(atof(p));
seek_time = SongTime::FromS(ParseDouble(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))) {
@ -158,12 +159,12 @@ playlist_state_restore(const char *line, TextFile &file,
} 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));
pc.SetMixRampDb(ParseFloat(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));
pc.SetMixRampDelay(ParseFloat(p));
} else if ((p = StringAfterPrefix(line, PLAYLIST_STATE_FILE_RANDOM))) {
random_mode = StringIsEqual(p, "1");
} else if ((p = StringAfterPrefix(line, PLAYLIST_STATE_FILE_CURRENT))) {

View File

@ -22,6 +22,7 @@
#include "VorbisComment.hxx"
#include "ReplayGainInfo.hxx"
#include "util/ASCII.hxx"
#include "util/NumberParser.hxx"
#include <assert.h>
#include <stdlib.h>
@ -33,16 +34,16 @@ ParseReplayGainTagTemplate(ReplayGainInfo &info, const T t)
const char *value;
if ((value = t["replaygain_track_gain"]) != nullptr) {
info.track.gain = atof(value);
info.track.gain = ParseFloat(value);
return true;
} else if ((value = t["replaygain_album_gain"]) != nullptr) {
info.album.gain = atof(value);
info.album.gain = ParseFloat(value);
return true;
} else if ((value = t["replaygain_track_peak"]) != nullptr) {
info.track.peak = atof(value);
info.track.peak = ParseFloat(value);
return true;
} else if ((value = t["replaygain_album_peak"]) != nullptr) {
info.album.peak = atof(value);
info.album.peak = ParseFloat(value);
return true;
} else
return false;