FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_insert_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy) { FLAC__StreamMetadata_VorbisComment *vc; FLAC__ASSERT(0 != object); FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT); FLAC__ASSERT(comment_num <= object->data.vorbis_comment.num_comments); vc = &object->data.vorbis_comment; if(!FLAC__metadata_object_vorbiscomment_resize_comments(object, vc->num_comments+1)) return false; /* move all comments >= comment_num forward one space */ memmove(&vc->comments[comment_num+1], &vc->comments[comment_num], sizeof(FLAC__StreamMetadata_VorbisComment_Entry)*(vc->num_comments-1-comment_num)); vc->comments[comment_num].length = 0; vc->comments[comment_num].entry = 0; return FLAC__metadata_object_vorbiscomment_set_comment(object, comment_num, entry, copy); }
FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_replace_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool all, FLAC__bool copy) { FLAC__ASSERT(0 != entry.entry && entry.length > 0); if(!FLAC__format_vorbiscomment_entry_is_legal(entry.entry, entry.length)) return false; { int i; unsigned field_name_length; const FLAC__byte *eq = (FLAC__byte*)memchr(entry.entry, '=', entry.length); FLAC__ASSERT(0 != eq); if(0 == eq) return false; /* double protection */ field_name_length = eq-entry.entry; if((i = vorbiscomment_find_entry_from_(object, 0, (const char *)entry.entry, field_name_length)) >= 0) { unsigned index = (unsigned)i; if(!FLAC__metadata_object_vorbiscomment_set_comment(object, index, entry, copy)) return false; if(all && (index+1 < object->data.vorbis_comment.num_comments)) { for(i = vorbiscomment_find_entry_from_(object, index+1, (const char *)entry.entry, field_name_length); i >= 0; ) { if(!FLAC__metadata_object_vorbiscomment_delete_comment(object, (unsigned)i)) return false; if((unsigned)i < object->data.vorbis_comment.num_comments) i = vorbiscomment_find_entry_from_(object, (unsigned)i, (const char *)entry.entry, field_name_length); else i = -1; } } return true; } else return FLAC__metadata_object_vorbiscomment_append_comment(object, entry, copy); } }