diff options
author | Max Kellermann <max@duempel.org> | 2013-09-05 18:59:19 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-09-05 18:59:19 +0200 |
commit | ae5e0cb02bdc82b5848dc1641f8cbc48dadc2d76 (patch) | |
tree | 39e662bca225a7b981523066038dfb55a8ce3135 /src/SongSave.cxx | |
parent | 0b3e1c4706849be107954ad1b8d6bf82ef3dcc28 (diff) |
SongSave: use class TagBuilder
Diffstat (limited to 'src/SongSave.cxx')
-rw-r--r-- | src/SongSave.cxx | 32 |
1 files changed, 8 insertions, 24 deletions
diff --git a/src/SongSave.cxx b/src/SongSave.cxx index d46eea6af..751d53efb 100644 --- a/src/SongSave.cxx +++ b/src/SongSave.cxx @@ -24,6 +24,7 @@ #include "Directory.hxx" #include "TextFile.hxx" #include "tag/Tag.hxx" +#include "tag/TagBuilder.hxx" #include "util/StringUtil.hxx" #include "util/Error.hxx" #include "util/Domain.hxx" @@ -68,12 +69,12 @@ song_load(TextFile &file, Directory *parent, const char *uri, enum tag_type type; const char *value; + TagBuilder tag; + while ((line = file.ReadLine()) != NULL && strcmp(line, SONG_END) != 0) { colon = strchr(line, ':'); if (colon == NULL || colon == line) { - if (song->tag != NULL) - song->tag->EndAdd(); song->Free(); error.Format(song_save_domain, @@ -85,26 +86,11 @@ song_load(TextFile &file, Directory *parent, const char *uri, value = strchug_fast_c(colon); if ((type = tag_name_parse(line)) != TAG_NUM_OF_ITEM_TYPES) { - if (!song->tag) { - song->tag = new Tag(); - song->tag->BeginAdd(); - } - - song->tag->AddItem(type, value); + tag.AddItem(type, value); } else if (strcmp(line, "Time") == 0) { - if (!song->tag) { - song->tag = new Tag(); - song->tag->BeginAdd(); - } - - song->tag->time = atoi(value); + tag.SetTime(atoi(value)); } else if (strcmp(line, "Playlist") == 0) { - if (!song->tag) { - song->tag = new Tag(); - song->tag->BeginAdd(); - } - - song->tag->has_playlist = strcmp(value, "yes") == 0; + tag.SetHasPlaylist(strcmp(value, "yes") == 0); } else if (strcmp(line, SONG_MTIME) == 0) { song->mtime = atoi(value); } else if (strcmp(line, "Range") == 0) { @@ -114,8 +100,6 @@ song_load(TextFile &file, Directory *parent, const char *uri, if (*endptr == '-') song->end_ms = strtoul(endptr + 1, NULL, 10); } else { - if (song->tag != NULL) - song->tag->EndAdd(); song->Free(); error.Format(song_save_domain, @@ -124,8 +108,8 @@ song_load(TextFile &file, Directory *parent, const char *uri, } } - if (song->tag != NULL) - song->tag->EndAdd(); + if (tag.IsDefined()) + song->tag = tag.Commit(); return song; } |