[SCM] libav/experimental: av_get_token() based on a patch by Stefano Sabatini

siretart at users.alioth.debian.org siretart at users.alioth.debian.org
Sun Jun 30 16:45:13 UTC 2013


The following commit has been merged in the experimental branch:
commit d11dbf092c759bd050a7d22e2c2a7171fd4ad36f
Author: Michael Niedermayer <michaelni at gmx.at>
Date:   Fri May 1 14:38:07 2009 +0000

    av_get_token()
    based on a patch by Stefano Sabatini
    
    Originally committed as revision 18725 to svn://svn.ffmpeg.org/ffmpeg/trunk

diff --git a/libavfilter/parseutils.c b/libavfilter/parseutils.c
new file mode 100644
index 0000000..b74533b
--- /dev/null
+++ b/libavfilter/parseutils.c
@@ -0,0 +1,110 @@
+/*
+ * copyright (c) 2009 Stefano Sabatini
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file libavfilter/parseutils.c
+ * parsing utils
+ */
+
+#include <string.h>
+#include "libavutil/avutil.h"
+#include "parseutils.h"
+
+#define WHITESPACES " \n\t"
+
+char *av_get_token(const char **buf, const char *term)
+{
+    char *out = av_malloc(strlen(*buf) + 1);
+    char *ret= out, *end= out;
+    const char *p = *buf;
+    p += strspn(p, WHITESPACES);
+
+    while(*p && !strspn(p, term)) {
+        char c = *p++;
+        if(c == '\\' && *p){
+            *out++ = *p++;
+            end= out;
+        }else if(c == '\''){
+            while(*p && *p != '\'')
+                *out++ = *p++;
+            if(*p){
+                p++;
+                end= out;
+            }
+        }else{
+            *out++ = c;
+        }
+    }
+
+    do{
+        *out-- = 0;
+    }while(out >= end && strspn(out, WHITESPACES));
+
+    *buf = p;
+
+    return ret;
+}
+
+#ifdef TEST
+
+#undef printf
+
+int main()
+{
+    int i;
+
+    const char *strings[] = {
+        "''",
+        "",
+        ":",
+        "\\",
+        "'",
+        "    ''    :",
+        "    ''  ''  :",
+        "foo   '' :",
+        "'foo'",
+        "foo     ",
+        "foo\\",
+        "foo':  blah:blah",
+        "foo\\:  blah:blah",
+        "foo\'",
+        "'foo :  '  :blahblah",
+        "\\ :blah",
+        "     foo",
+        "      foo       ",
+        "      foo     \\ ",
+        "foo ':blah",
+        " foo   bar    :   blahblah",
+        "\\f\\o\\o",
+        "'foo : \\ \\  '   : blahblah",
+        "'\\fo\\o:': blahblah",
+        "\\'fo\\o\\:':  foo  '  :blahblah"
+    };
+
+    for (i=0; i < FF_ARRAY_ELEMS(strings); i++) {
+        const char *p= strings[i];
+        printf("|%s|", p);
+        printf(" -> |%s|", av_get_token(&p, ":"));
+        printf(" + |%s|\n", p);
+    }
+
+    return 0;
+}
+
+#endif
diff --git a/libavformat/rtp_asf.h b/libavfilter/parseutils.h
similarity index 53%
copy from libavformat/rtp_asf.h
copy to libavfilter/parseutils.h
index 2898894..60092cc 100644
--- a/libavformat/rtp_asf.h
+++ b/libavfilter/parseutils.h
@@ -1,7 +1,5 @@
 /*
- * Microsoft RTP/ASF support.
- * Copyright (c) 2008 Ronald S. Bultje
- *
+ * copyright (c) 2009 Stefano Sabatini
  * This file is part of FFmpeg.
  *
  * FFmpeg is free software; you can redistribute it and/or
@@ -19,25 +17,27 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#ifndef AVFORMAT_RTP_ASF_H
-#define AVFORMAT_RTP_ASF_H
-
-#include "avformat.h"
-#include "rtpdec.h"
-
 /**
- * Parse a Windows Media Server-specific SDP line
- *
- * @param s RTSP demux context
- * @param line the SDP line to be parsed
+ * @file libavfilter/parseutils.h
+ * parsing utils
  */
-void ff_wms_parse_sdp_a_line(AVFormatContext *s, const char *p);
+
+#ifndef AVFILTER_PARSEUTILS_H
+#define AVFILTER_PARSEUTILS_H
 
 /**
- * Handlers for the x-asf-pf payloads (the payload ID for RTP/ASF).
- * Defined and implemented in rtp_asf.c, registered in rtpdec.c.
+ * Unescapes the given string until a non escaped terminating char,
+ * and returns the token corresponding to the unescaped string.
+ *
+ * The normal \ and ' escaping is supported. Leading and trailing
+ * whitespaces are removed.
+ *
+ * @param term a 0-terminated list of terminating chars
+ * @param buf the buffer to parse, buf will be updated to point to the
+ * terminating char
+ * @return the malloced unescaped string, which must be av_freed by
+ * the user
  */
-extern RTPDynamicProtocolHandler ff_ms_rtp_asf_pfv_handler,
-                                 ff_ms_rtp_asf_pfa_handler;
+char *av_get_token(const char **buf, const char *term);
 
-#endif /* AVFORMAT_RTP_ASF_H */
+#endif  /* AVFILTER_PARSEUTILS_H */

-- 
Libav/FFmpeg packaging



More information about the pkg-multimedia-commits mailing list