struct id3_frame *MakeID3Frame(const char *name, const char *data0, const char *data1) { struct id3_frame *frame; id3_latin1_t *latin1; id3_ucs4_t *ucs4; frame = id3_frame_new(name); latin1 = (id3_latin1_t *)data1; ucs4 = (id3_ucs4_t *)malloc((id3_latin1_length(latin1) + 1) * sizeof(*ucs4)); id3_latin1_decode(latin1, ucs4); if (strcmp(name, ID3_FRAME_COMMENT) == 0) { id3_field_setfullstring(&frame->fields[3], ucs4); } else if (strcmp(name, "TXXX") == 0) { id3_field_setstring(&frame->fields[2], ucs4); if (data0) { free(ucs4); latin1 = (id3_latin1_t *)data0; ucs4 = (id3_ucs4_t *)malloc((id3_latin1_length(latin1) + 1) * sizeof(*ucs4)); id3_latin1_decode(latin1, ucs4); id3_field_setstring(&frame->fields[1], ucs4); } } else id3_field_setstrings(&frame->fields[1], 1, &ucs4); free(ucs4); return frame; }
/* * NAME: latin1->deserialize() * DESCRIPTION: deserialize a ucs4 string using latin1 encoding */ id3_ucs4_t *id3_latin1_deserialize(id3_byte_t const **ptr, id3_length_t length) { id3_byte_t const *end; id3_latin1_t *latin1ptr, *latin1; id3_ucs4_t *ucs4; end = *ptr + length; latin1 = malloc((length + 1) * sizeof(*latin1)); if (latin1 == 0) return 0; latin1ptr = latin1; while (end - *ptr > 0 && (*latin1ptr = id3_latin1_get(ptr))) ++latin1ptr; *latin1ptr = 0; ucs4 = malloc((id3_latin1_length(latin1) + 1) * sizeof(*ucs4)); if (ucs4) id3_latin1_decode(latin1, ucs4); free(latin1); return ucs4; }
wxString GetGenreNum(int i) { #ifdef USE_LIBID3TAG id3_latin1_t i_latin1[50]; id3_ucs4_t *i_ucs4; const id3_ucs4_t *genre_ucs4; sprintf((char *)i_latin1, "%d", i); i_ucs4 = (id3_ucs4_t *)malloc((id3_latin1_length(i_latin1) + 1) * sizeof(*i_ucs4)); if (i_ucs4) { id3_latin1_decode(i_latin1, i_ucs4); genre_ucs4 = id3_genre_name(i_ucs4); char *genre_char = (char *)id3_ucs4_utf8duplicate(genre_ucs4); wxString genreStr = UTF8CTOWX(genre_char); free(genre_char); free(i_ucs4); return genreStr; } #endif // ifdef USE_LIBID3TAG return wxT(""); }
/* * NAME: latin1->ucs4duplicate() * DESCRIPTION: duplicate and decode a latin1 string into ucs4 */ id3_ucs4_t *id3_latin1_ucs4duplicate(id3_latin1_t const *latin1) { id3_ucs4_t *ucs4; ucs4 = malloc((id3_latin1_length(latin1) + 1) * sizeof(*ucs4)); if (ucs4) id3_latin1_decode(latin1, ucs4); return release(ucs4); }
static int v1_attachstr(struct id3_tag *tag, char const *id, char *text, unsigned long number) { struct id3_frame *frame; id3_ucs4_t ucs4[31]; if (text) { trim(text); if (*text == 0) return 0; } frame = id3_frame_new(id); if (frame == 0) return -1; if (id3_field_settextencoding(&frame->fields[0], ID3_FIELD_TEXTENCODING_ISO_8859_1) == -1) goto fail; if (text) id3_latin1_decode(text, ucs4); else id3_ucs4_putnumber(ucs4, number); if (strcmp(id, ID3_FRAME_COMMENT) == 0) { if (id3_field_setlanguage(&frame->fields[1], "XXX") == -1 || id3_field_setstring(&frame->fields[2], id3_ucs4_empty) == -1 || id3_field_setfullstring(&frame->fields[3], ucs4) == -1) goto fail; } else { id3_ucs4_t *ptr = ucs4; if (id3_field_setstrings(&frame->fields[1], 1, &ptr) == -1) goto fail; } if (id3_tag_attachframe(tag, frame) == -1) goto fail; return 0; fail: id3_frame_delete(frame); return -1; }