tag/VorbisComment: use struct StringView

This commit is contained in:
Max Kellermann
2019-08-14 11:33:00 +02:00
parent 8e0d810968
commit 9ae9b2c18f
7 changed files with 34 additions and 34 deletions
+2 -2
View File
@@ -72,8 +72,8 @@ ParseMixRampVorbis(MixRampInfo &info, const char *entry)
const char *entry;
gcc_pure
StringView operator[](const char *n) const noexcept {
return vorbis_comment_value(entry, n);
StringView operator[](StringView n) const noexcept {
return GetVorbisCommentValue(entry, n);
}
};
+4 -4
View File
@@ -70,14 +70,14 @@ ParseReplayGainTag(ReplayGainInfo &info, const char *name, const char *value)
}
bool
ParseReplayGainVorbis(ReplayGainInfo &info, const char *entry)
ParseReplayGainVorbis(ReplayGainInfo &info, StringView entry)
{
struct VorbisCommentEntry {
const char *entry;
StringView entry;
gcc_pure
const char *operator[](const char *n) const noexcept {
return vorbis_comment_value(entry, n);
const char *operator[](StringView n) const noexcept {
return GetVorbisCommentValue(entry, n).data;
}
};
+2 -1
View File
@@ -20,12 +20,13 @@
#ifndef MPD_TAG_REPLAY_GAIN_HXX
#define MPD_TAG_REPLAY_GAIN_HXX
struct StringView;
struct ReplayGainInfo;
bool
ParseReplayGainTag(ReplayGainInfo &info, const char *name, const char *value);
bool
ParseReplayGainVorbis(ReplayGainInfo &info, const char *entry);
ParseReplayGainVorbis(ReplayGainInfo &info, StringView entry);
#endif
+10 -12
View File
@@ -18,23 +18,21 @@
*/
#include "VorbisComment.hxx"
#include "util/ASCII.hxx"
#include "util/StringView.hxx"
#include <assert.h>
#include <string.h>
const char *
vorbis_comment_value(const char *entry, const char *name) noexcept
StringView
GetVorbisCommentValue(StringView entry, StringView name) noexcept
{
assert(entry != nullptr);
assert(name != nullptr);
assert(*name != 0);
assert(!name.empty());
const size_t length = strlen(name);
if (StringEqualsCaseASCII(entry, name, length) &&
entry[length] == '=')
return entry + length + 1;
if (entry.StartsWithIgnoreCase(name) &&
entry.size > name.size &&
entry[name.size] == '=') {
entry.skip_front(name.size + 1);
return entry;
}
return nullptr;
}
+4 -2
View File
@@ -22,12 +22,14 @@
#include "util/Compiler.h"
struct StringView;
/**
* Checks if the specified name matches the entry's name, and if yes,
* returns the comment value.
*/
gcc_pure
const char *
vorbis_comment_value(const char *entry, const char *name) noexcept;
StringView
GetVorbisCommentValue(StringView entry, StringView name) noexcept;
#endif