[FFmpeg-devel] [PATCH 3/4] Move av_get_token() from libavfilter to libavutil.

Stefano Sabatini stefano.sabatini-lala
Sat Jun 12 20:28:42 CEST 2010


This may be useful also outside libavfilter. Note that this breaks the
libavfilter ABI, but we don't care as its ABI is yet considered
unstable.
---
 libavfilter/parseutils.c |   36 +-----------------------------------
 libavfilter/parseutils.h |   15 ---------------
 libavutil/avstring.c     |   35 +++++++++++++++++++++++++++++++++++
 libavutil/avstring.h     |   15 +++++++++++++++
 4 files changed, 51 insertions(+), 50 deletions(-)

diff --git a/libavfilter/parseutils.c b/libavfilter/parseutils.c
index 9ac61d8..7f30dfa 100644
--- a/libavfilter/parseutils.c
+++ b/libavfilter/parseutils.c
@@ -24,44 +24,10 @@
 
 #include <strings.h>
 #include "libavutil/avutil.h"
+#include "libavutil/avstring.h"
 #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;
-    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     rgba_color[4];   ///< RGBA values for the color
diff --git a/libavfilter/parseutils.h b/libavfilter/parseutils.h
index b5b494e..30bbc19 100644
--- a/libavfilter/parseutils.h
+++ b/libavfilter/parseutils.h
@@ -28,21 +28,6 @@
 #include "libavcodec/opt.h"
 
 /**
- * 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
- */
-char *av_get_token(const char **buf, const char *term);
-
-/**
  * Puts 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/libavutil/avstring.c b/libavutil/avstring.c
index 4844e28..667558a 100644
--- a/libavutil/avstring.c
+++ b/libavutil/avstring.c
@@ -97,3 +97,38 @@ 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;
+    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..042d171 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);
 
+/**
+ * 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
+ */
+char *av_get_token(const char **buf, const char *term);
+
 #endif /* AVUTIL_AVSTRING_H */
-- 
1.7.1




More information about the ffmpeg-devel mailing list