diff options
author | Max Kellermann <max@musicpd.org> | 2019-08-14 11:33:00 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2019-08-14 12:22:52 +0200 |
commit | 9ae9b2c18fd37a7a48ff197f9a979bfd18110cab (patch) | |
tree | 377eb641c94b5ead4adc88166f69cad098d8696f /src/tag | |
parent | 8e0d81096894d37b4aa3a95ee0ca798cec7f4680 (diff) |
tag/VorbisComment: use struct StringView
Diffstat (limited to 'src/tag')
-rw-r--r-- | src/tag/MixRamp.cxx | 4 | ||||
-rw-r--r-- | src/tag/ReplayGain.cxx | 8 | ||||
-rw-r--r-- | src/tag/ReplayGain.hxx | 3 | ||||
-rw-r--r-- | src/tag/VorbisComment.cxx | 22 | ||||
-rw-r--r-- | src/tag/VorbisComment.hxx | 6 |
5 files changed, 22 insertions, 21 deletions
diff --git a/src/tag/MixRamp.cxx b/src/tag/MixRamp.cxx index a0e1457de..876061410 100644 --- a/src/tag/MixRamp.cxx +++ b/src/tag/MixRamp.cxx @@ -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); } }; diff --git a/src/tag/ReplayGain.cxx b/src/tag/ReplayGain.cxx index 92eb7c925..f23f23e3c 100644 --- a/src/tag/ReplayGain.cxx +++ b/src/tag/ReplayGain.cxx @@ -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; } }; diff --git a/src/tag/ReplayGain.hxx b/src/tag/ReplayGain.hxx index 4f231f5f6..db0b4a715 100644 --- a/src/tag/ReplayGain.hxx +++ b/src/tag/ReplayGain.hxx @@ -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 diff --git a/src/tag/VorbisComment.cxx b/src/tag/VorbisComment.cxx index c87d393e8..dc9e822fe 100644 --- a/src/tag/VorbisComment.cxx +++ b/src/tag/VorbisComment.cxx @@ -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; } diff --git a/src/tag/VorbisComment.hxx b/src/tag/VorbisComment.hxx index 6b45c1737..83c3a7fa6 100644 --- a/src/tag/VorbisComment.hxx +++ b/src/tag/VorbisComment.hxx @@ -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 |