diff options
author | Warren Dukes <warren.dukes@gmail.com> | 2004-11-10 02:38:55 +0000 |
---|---|---|
committer | Warren Dukes <warren.dukes@gmail.com> | 2004-11-10 02:38:55 +0000 |
commit | 2d87ffa863b5eaa24862e925e767eb9a36bd58fe (patch) | |
tree | 98028112defc0aedfe282b88c8ba81b15ffdd53b /src/tag.c | |
parent | 92a75471505391edd2f8f9af23188b4f7b17bbcb (diff) | |
download | mpd-2d87ffa863b5eaa24862e925e767eb9a36bd58fe.tar.gz mpd-2d87ffa863b5eaa24862e925e767eb9a36bd58fe.tar.xz mpd-2d87ffa863b5eaa24862e925e767eb9a36bd58fe.zip |
now we only allocate unique metadata items
git-svn-id: https://svn.musicpd.org/mpd/branches/r2562-metadata-handling-rewrite@2568 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/tag.c')
-rw-r--r-- | src/tag.c | 47 |
1 files changed, 24 insertions, 23 deletions
@@ -25,6 +25,7 @@ #include "inputStream.h" #include "conf.h" #include "charConv.h" +#include "tagTracker.h" #include <sys/stat.h> #include <stdlib.h> @@ -62,25 +63,6 @@ void printMpdTag(FILE * fp, MpdTag * tag) { } } -#define fixUtf8(str) { \ - if(str && !validUtf8String(str)) { \ - char * temp; \ - DEBUG("not valid utf8 in tag: %s\n",str); \ - temp = latin1StrToUtf8Dup(str); \ - free(str); \ - str = temp; \ - } \ -} - -void validateUtf8Tag(MpdTag * tag) { - int i; - - for(i = 0; i < tag->numOfItems; i++) { - fixUtf8(tag->items[i].value); - stripReturnChar(tag->items[i].value); - } -} - #ifdef HAVE_ID3TAG MpdTag * getID3Info(struct id3_tag * tag, char * id, int type, MpdTag * mpdTag) { @@ -172,6 +154,8 @@ MpdTag * newMpdTag() { static void deleteItem(MpdTag * tag, int index) { tag->numOfItems--; + removeTagItemString(tag->items[index].type, tag->items[index].value); + if(tag->numOfItems-index > 0) { memmove(tag->items+index, tag->items+index+1, tag->numOfItems-index); @@ -203,7 +187,7 @@ void clearMpdTag(MpdTag * tag) { int i; for(i = 0; i < tag->numOfItems; i++) { - free(tag->items[i].value); + removeTagItemString(tag->items[i].type, tag->items[i].value); } if(tag->items) free(tag->items); @@ -255,18 +239,35 @@ int mpdTagsAreEqual(MpdTag * tag1, MpdTag * tag2) { return 1; } +#define fixUtf8(str) { \ + if(str && !validUtf8String(str)) { \ + char * temp; \ + DEBUG("not valid utf8 in tag: %s\n",str); \ + temp = latin1StrToUtf8Dup(str); \ + free(str); \ + str = temp; \ + } \ +} + inline static void appendToTagItems(MpdTag * tag, int type, char * value, int len) { int i = tag->numOfItems; + char * temp; + temp = malloc(len+1); + strncpy(temp, value, len); + temp[len] = '\0'; + + fixUtf8(temp); + tag->numOfItems++; tag->items = realloc(tag->items, tag->numOfItems*sizeof(MpdTagItem)); tag->items[i].type = type; - tag->items[i].value = malloc(len+1); - strncpy(tag->items[i].value, value, len); - tag->items[i].value[len] = '\0'; + tag->items[i].value = getTagItemString(type, value); + + free(temp); } void addItemToMpdTagWithLen(MpdTag * tag, int itemType, char * value, int len) { |