[PATCH] Move av_get_token() from libavfilter to libavutil.

Stefano Sabatini stefano.sabatini-lala
Mon Sep 27 11:56:48 CEST 2010


---
 libavfilter/graphparser.c |    1 +
 libavfilter/parseutils.c  |   36 ------------------------------------
 libavfilter/parseutils.h  |   15 ---------------
 libavfilter/vf_frei0r.c   |    1 +
 libavutil/avstring.c      |   36 ++++++++++++++++++++++++++++++++++++
 libavutil/avstring.h      |   15 +++++++++++++++
 6 files changed, 53 insertions(+), 51 deletions(-)

diff --git a/libavfilter/graphparser.c b/libavfilter/graphparser.c
index c4f621b..fab0423 100644
--- a/libavfilter/graphparser.c
+++ b/libavfilter/graphparser.c
@@ -23,6 +23,7 @@
 #include <ctype.h>
 #include <string.h>
 
+#include "libavutil/avstring.h"
 #include "graphparser.h"
 #include "avfilter.h"
 #include "avfiltergraph.h"
diff --git a/libavfilter/parseutils.c b/libavfilter/parseutils.c
index 669ec9d..c56f541 100644
--- a/libavfilter/parseutils.c
+++ b/libavfilter/parseutils.c
@@ -28,42 +28,6 @@
 #include "libavutil/random_seed.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;
-    if (!out) return NULL;
-    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;
-}
-
 typedef struct {
     const char *name;            ///< a string representing the name of the color
     uint8_t     rgb_color[3];    ///< RGB values for the color
diff --git a/libavfilter/parseutils.h b/libavfilter/parseutils.h
index a139c95..59c5262 100644
--- a/libavfilter/parseutils.h
+++ b/libavfilter/parseutils.h
@@ -28,21 +28,6 @@
 #include "libavutil/opt.h"
 
 /**
- * Unescape the given string until a non escaped terminating char,
- * and return the token corresponding to the unescaped string.
- *
- * The normal \ and ' escaping is supported. Leading and trailing
- * whitespaces are removed.
- *
- * @param buf the buffer to parse, buf will be updated to point to the
- * terminating char
- * @param term a 0-terminated list of terminating chars
- * @return the malloced unescaped string, which must be av_freed by
- * the user, NULL in case of allocation failure
- */
-char *av_get_token(const char **buf, const char *term);
-
-/**
  * Put the RGBA values that correspond to color_string in rgba_color.
  *
  * @param color_string a string specifying a color. It can be the name of
diff --git a/libavfilter/vf_frei0r.c b/libavfilter/vf_frei0r.c
index 4ad7125..1303b03 100644
--- a/libavfilter/vf_frei0r.c
+++ b/libavfilter/vf_frei0r.c
@@ -26,6 +26,7 @@
 
 #include <dlfcn.h>
 #include <frei0r.h>
+#include "libavutil/avstring.h"
 #include "avfilter.h"
 #include "parseutils.h"
 
diff --git a/libavutil/avstring.c b/libavutil/avstring.c
index 4844e28..7f00e55 100644
--- a/libavutil/avstring.c
+++ b/libavutil/avstring.c
@@ -97,3 +97,39 @@ char *av_d2str(double d)
     if(str) snprintf(str, 16, "%f", d);
     return str;
 }
+
+#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;
+    if (!out) return NULL;
+    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;
+}
diff --git a/libavutil/avstring.h b/libavutil/avstring.h
index 01c2391..f1d8638 100644
--- a/libavutil/avstring.h
+++ b/libavutil/avstring.h
@@ -114,4 +114,19 @@ size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...);
  */
 char *av_d2str(double d);
 
+/**
+ * Unescape the given string until a non escaped terminating char,
+ * and return the token corresponding to the unescaped string.
+ *
+ * The normal \ and ' escaping is supported. Leading and trailing
+ * whitespaces are removed.
+ *
+ * @param buf the buffer to parse, buf will be updated to point to the
+ * terminating char
+ * @param term a 0-terminated list of terminating chars
+ * @return the malloced unescaped string, which must be av_freed by
+ * the user, NULL in case of allocation failure
+ */
+char *av_get_token(const char **buf, const char *term);
+
 #endif /* AVUTIL_AVSTRING_H */
-- 
1.7.1


--MGYHOYXEY6WxJCY8--



More information about the ffmpeg-devel mailing list