Added new function vorbis_comment_query_count(), after a couple of people requested...
authorMike Smith <msmith@xiph.org>
Sun, 13 Aug 2000 13:55:41 +0000 (13:55 +0000)
committerMike Smith <msmith@xiph.org>
Sun, 13 Aug 2000 13:55:41 +0000 (13:55 +0000)
svn path=/trunk/vorbis/; revision=550

include/vorbis/codec.h
lib/info.c

index 74c3729..a0d04e0 100644 (file)
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: libvorbis codec headers
- last mod: $Id: codec.h,v 1.23 2000/08/04 01:05:45 xiphmont Exp $
+ last mod: $Id: codec.h,v 1.24 2000/08/13 13:55:41 msmith Exp $
 
  ********************************************************************/
 
@@ -403,6 +403,7 @@ extern void     vorbis_comment_add(vorbis_comment *vc, char *comment);
 extern void     vorbis_comment_add_tag(vorbis_comment *vc, 
                                       char *tag, char *contents);
 extern char    *vorbis_comment_query(vorbis_comment *vc, char *tag, int count);
+extern int      vorbis_comment_query_count(vorbis_comment *vc, char *tag);
 extern void     vorbis_comment_clear(vorbis_comment *vc);
 
 extern int      vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb);
index 3a84e88..9536684 100644 (file)
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: maintain the info structure, info <-> header packets
- last mod: $Id: info.c,v 1.28 2000/08/01 13:45:13 msmith Exp $
+ last mod: $Id: info.c,v 1.29 2000/08/13 13:55:39 msmith Exp $
 
  ********************************************************************/
 
@@ -93,8 +93,8 @@ static int tagcompare(const char *s1, const char *s2, int n){
 char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){
   long i;
   int found = 0;
-  int taglen = strlen(tag);
-  char *fulltag = alloca(taglen+ 2);
+  int taglen = strlen(tag)+1; /* +1 for the = we append */
+  char *fulltag = alloca(taglen+ 1);
 
   strcpy(fulltag, tag);
   strcat(fulltag, "=");
@@ -103,7 +103,7 @@ char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){
     if(!tagcompare(vc->user_comments[i], fulltag, taglen)){
       if(count == found)
        /* We return a pointer to the data, not a copy */
-       return vc->user_comments[i] + taglen + 1;
+       return vc->user_comments[i] + taglen;
       else
        found++;
     }
@@ -111,6 +111,22 @@ char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){
   return NULL; /* didn't find anything */
 }
 
+int vorbis_comment_query_count(vorbis_comment *vc, char *tag){
+  int i,count=0;
+  int taglen = strlen(tag)+1; /* +1 for the = we append */
+  char *fulltag = alloca(taglen+1);
+  strcpy(fulltag,tag);
+  strcat(fulltag, "=");
+
+  for(i=0;i<vc->comments;i++){
+    if(!tagcompare(vc->user_comments[i], fulltag, taglen))
+      count++;
+  }
+
+  return count;
+}
+
+
 void vorbis_comment_clear(vorbis_comment *vc){
   if(vc){
     long i;