diff options
-rw-r--r-- | src/input/IcyInputStream.cxx | 12 | ||||
-rw-r--r-- | src/tag/Tag.cxx | 16 | ||||
-rw-r--r-- | src/tag/Tag.hxx | 9 |
3 files changed, 26 insertions, 11 deletions
diff --git a/src/input/IcyInputStream.cxx b/src/input/IcyInputStream.cxx index 631d935c0..1c114e589 100644 --- a/src/input/IcyInputStream.cxx +++ b/src/input/IcyInputStream.cxx @@ -82,17 +82,7 @@ IcyInputStream::ReadTag() noexcept /* no change */ return nullptr; - if (input_tag == nullptr && icy_tag == nullptr) - /* no tag */ - return nullptr; - - if (input_tag == nullptr) - return std::make_unique<Tag>(*icy_tag); - - if (icy_tag == nullptr) - return std::make_unique<Tag>(*input_tag); - - return Tag::MergePtr(*input_tag, *icy_tag); + return Tag::Merge(input_tag.get(), icy_tag.get()); } size_t diff --git a/src/tag/Tag.cxx b/src/tag/Tag.cxx index 5abb6d7f1..a9b8479f5 100644 --- a/src/tag/Tag.cxx +++ b/src/tag/Tag.cxx @@ -81,6 +81,22 @@ Tag::Merge(std::unique_ptr<Tag> base, std::unique_ptr<Tag> add) noexcept return MergePtr(*base, *add); } +std::unique_ptr<Tag> +Tag::Merge(const Tag *base, const Tag *add) noexcept +{ + if (base == nullptr && add == nullptr) + /* no tag */ + return nullptr; + + if (base == nullptr) + return std::make_unique<Tag>(*add); + + if (add == nullptr) + return std::make_unique<Tag>(*base); + + return MergePtr(*base, *add); +} + const char * Tag::GetValue(TagType type) const noexcept { diff --git a/src/tag/Tag.hxx b/src/tag/Tag.hxx index fca5ea284..aa409e2c1 100644 --- a/src/tag/Tag.hxx +++ b/src/tag/Tag.hxx @@ -133,6 +133,15 @@ struct Tag { std::unique_ptr<Tag> add) noexcept; /** + * Merges the data from two tags. Any of the two may be nullptr. + * + * @return a newly allocated tag (or nullptr if both + * parameters are nullptr) + */ + static std::unique_ptr<Tag> Merge(const Tag *base, + const Tag *add) noexcept; + + /** * Returns the first value of the specified tag type, or * nullptr if none is present in this tag object. */ |