Commit 9f4fc8ad authored by Max Kellermann's avatar Max Kellermann

tag/ReplayGain: move code to template function

parent d1e31261
...@@ -25,24 +25,46 @@ ...@@ -25,24 +25,46 @@
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
bool template<typename T>
ParseReplayGainTag(ReplayGainInfo &info, const char *name, const char *value) static bool
ParseReplayGainTagTemplate(ReplayGainInfo &info, const T t)
{ {
assert(name != nullptr); const char *value;
assert(value != nullptr);
if (StringEqualsCaseASCII(name, "replaygain_track_gain")) { if ((value = t["replaygain_track_gain"]) != nullptr) {
info.tuples[REPLAY_GAIN_TRACK].gain = atof(value); info.tuples[REPLAY_GAIN_TRACK].gain = atof(value);
return true; return true;
} else if (StringEqualsCaseASCII(name, "replaygain_album_gain")) { } else if ((value = t["replaygain_album_gain"]) != nullptr) {
info.tuples[REPLAY_GAIN_ALBUM].gain = atof(value); info.tuples[REPLAY_GAIN_ALBUM].gain = atof(value);
return true; return true;
} else if (StringEqualsCaseASCII(name, "replaygain_track_peak")) { } else if ((value = t["replaygain_track_peak"]) != nullptr) {
info.tuples[REPLAY_GAIN_TRACK].peak = atof(value); info.tuples[REPLAY_GAIN_TRACK].peak = atof(value);
return true; return true;
} else if (StringEqualsCaseASCII(name, "replaygain_album_peak")) { } else if ((value = t["replaygain_album_peak"]) != nullptr) {
info.tuples[REPLAY_GAIN_ALBUM].peak = atof(value); info.tuples[REPLAY_GAIN_ALBUM].peak = atof(value);
return true; return true;
} else } else
return false; return false;
}
bool
ParseReplayGainTag(ReplayGainInfo &info, const char *name, const char *value)
{
assert(name != nullptr);
assert(value != nullptr);
struct NameValue {
const char *name;
const char *value;
gcc_pure
const char *operator[](const char *n) const {
return StringEqualsCaseASCII(name, n)
? value
: nullptr;
}
};
return ParseReplayGainTagTemplate(info, NameValue{name, value});
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment