diff options
Diffstat (limited to 'src/cue/CueParser.cxx')
-rw-r--r-- | src/cue/CueParser.cxx | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/src/cue/CueParser.cxx b/src/cue/CueParser.cxx index 60b33b6b4..4a4f823ab 100644 --- a/src/cue/CueParser.cxx +++ b/src/cue/CueParser.cxx @@ -19,19 +19,18 @@ #include "config.h" #include "CueParser.hxx" +#include "util/Alloc.hxx" #include "util/StringUtil.hxx" #include "util/CharUtil.hxx" #include "Song.hxx" #include "tag/Tag.hxx" -#include <glib.h> - #include <assert.h> #include <string.h> #include <stdlib.h> CueParser::CueParser() - :state(HEADER), tag(new Tag()), + :state(HEADER), current(nullptr), previous(nullptr), finished(nullptr), @@ -39,8 +38,6 @@ CueParser::CueParser() CueParser::~CueParser() { - delete tag; - if (current != nullptr) current->Free(); @@ -109,7 +106,7 @@ cue_next_value(char **pp) } static void -cue_add_tag(Tag &tag, TagType type, char *p) +cue_add_tag(TagBuilder &tag, TagType type, char *p) { const char *value = cue_next_value(&p); if (value != nullptr) @@ -118,7 +115,7 @@ cue_add_tag(Tag &tag, TagType type, char *p) } static void -cue_parse_rem(char *p, Tag &tag) +cue_parse_rem(char *p, TagBuilder &tag) { const char *type = cue_next_token(&p); if (type == nullptr) @@ -129,13 +126,13 @@ cue_parse_rem(char *p, Tag &tag) cue_add_tag(tag, type2, p); } -Tag * +TagBuilder * CueParser::GetCurrentTag() { if (state == HEADER) - return tag; + return &header_tag; else if (state == TRACK) - return current->tag; + return &song_tag; else return nullptr; } @@ -172,6 +169,9 @@ CueParser::Commit() if (current == nullptr) return; + assert(current->tag == nullptr); + current->tag = song_tag.CommitNew(); + finished = previous; previous = current; current = nullptr; @@ -188,9 +188,9 @@ CueParser::Feed2(char *p) return; if (strcmp(command, "REM") == 0) { - Tag *current_tag = GetCurrentTag(); - if (current_tag != nullptr) - cue_parse_rem(p, *current_tag); + TagBuilder *tag = GetCurrentTag(); + if (tag != nullptr) + cue_parse_rem(p, *tag); } else if (strcmp(command, "PERFORMER") == 0) { /* MPD knows a "performer" tag, but it is not a good match for this CUE tag; from the Hydrogenaudio @@ -202,14 +202,14 @@ CueParser::Feed2(char *p) ? TAG_ARTIST : TAG_ALBUM_ARTIST; - Tag *current_tag = GetCurrentTag(); - if (current_tag != nullptr) - cue_add_tag(*current_tag, type, p); + TagBuilder *tag = GetCurrentTag(); + if (tag != nullptr) + cue_add_tag(*tag, type, p); } else if (strcmp(command, "TITLE") == 0) { if (state == HEADER) - cue_add_tag(*tag, TAG_ALBUM, p); + cue_add_tag(header_tag, TAG_ALBUM, p); else if (state == TRACK) - cue_add_tag(*current->tag, TAG_TITLE, p); + cue_add_tag(song_tag, TAG_TITLE, p); } else if (strcmp(command, "FILE") == 0) { Commit(); @@ -251,8 +251,10 @@ CueParser::Feed2(char *p) state = TRACK; current = Song::NewRemote(filename.c_str()); assert(current->tag == nullptr); - current->tag = new Tag(*tag); - current->tag->AddItem(TAG_TRACK, nr); + + song_tag = header_tag; + song_tag.AddItem(TAG_TRACK, nr); + last_updated = false; } else if (state == IGNORE_TRACK) { return; @@ -287,9 +289,9 @@ CueParser::Feed(const char *line) assert(!end); assert(line != nullptr); - char *allocated = g_strdup(line); + char *allocated = xstrdup(line); Feed2(allocated); - g_free(allocated); + free(allocated); } void |