Commit 2e72a9b2 authored by Max Kellermann's avatar Max Kellermann

tag: added function tag_merge_replace()

Like tag_merge(), but can deal with NULL parameters, and frees both tag objects.
parent 96033e4b
...@@ -173,7 +173,6 @@ cue_tag_file( FILE* fp, ...@@ -173,7 +173,6 @@ cue_tag_file( FILE* fp,
{ {
struct tag* cd_tag = NULL; struct tag* cd_tag = NULL;
struct tag* track_tag = NULL; struct tag* track_tag = NULL;
struct tag* merge_tag = NULL;
struct Cd* cd = NULL; struct Cd* cd = NULL;
if (tnum > 256) if (tnum > 256)
...@@ -199,26 +198,7 @@ cue_tag_file( FILE* fp, ...@@ -199,26 +198,7 @@ cue_tag_file( FILE* fp,
cd_delete(cd); cd_delete(cd);
} }
if ((cd_tag != NULL) && (track_tag != NULL)) return tag_merge_replace(cd_tag, track_tag);
{
merge_tag = tag_merge(cd_tag, track_tag);
tag_free(cd_tag);
tag_free(track_tag);
return merge_tag;
}
else if (cd_tag != NULL)
{
return cd_tag;
}
else if (track_tag != NULL)
{
return track_tag;
}
else
return NULL;
} }
struct tag* struct tag*
......
...@@ -247,6 +247,22 @@ tag_merge(const struct tag *base, const struct tag *add) ...@@ -247,6 +247,22 @@ tag_merge(const struct tag *base, const struct tag *add)
return ret; return ret;
} }
struct tag *
tag_merge_replace(struct tag *base, struct tag *add)
{
if (add == NULL)
return base;
if (base == NULL)
return add;
struct tag *tag = tag_merge(base, add);
tag_free(base);
tag_free(add);
return tag;
}
const char * const char *
tag_get_value(const struct tag *tag, enum tag_type type) tag_get_value(const struct tag *tag, enum tag_type type)
{ {
......
...@@ -166,6 +166,15 @@ struct tag * ...@@ -166,6 +166,15 @@ struct tag *
tag_merge(const struct tag *base, const struct tag *add); tag_merge(const struct tag *base, const struct tag *add);
/** /**
* Merges the data from two tags. Any of the two may be NULL. Both
* are freed by this function.
*
* @return a newly allocated tag, which must be freed with tag_free()
*/
struct tag *
tag_merge_replace(struct tag *base, struct tag *add);
/**
* Returns true if the tag contains no items. This ignores the "time" * Returns true if the tag contains no items. This ignores the "time"
* attribute. * attribute.
*/ */
......
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