summaryrefslogtreecommitdiff
path: root/libavfilter
diff options
context:
space:
mode:
authorVitor Sessak <vitor1001@gmail.com>2008-05-24 20:39:12 +0000
committerVitor Sessak <vitor1001@gmail.com>2008-05-24 20:39:12 +0000
commit93b7a0f68d772871c93ffb23a7d2524485b96a52 (patch)
treee06babc4a7dc1d2ca69897fd7469b23e66afe1e5 /libavfilter
parent5b2bb2c906d1b20234c22e2ce21cc9d9a7b4a44a (diff)
Simplify consume_string() as Michael suggested
Commited in SoC by Vitor Sessak on 2008-04-06 18:43:02 Originally committed as revision 13293 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavfilter')
-rw-r--r--libavfilter/graphparser.c77
1 files changed, 25 insertions, 52 deletions
diff --git a/libavfilter/graphparser.c b/libavfilter/graphparser.c
index abd88bac05..e784f8d3e2 100644
--- a/libavfilter/graphparser.c
+++ b/libavfilter/graphparser.c
@@ -94,68 +94,41 @@ static void consume_whitespace(const char **buf)
}
/**
- * Copy the first size bytes of input string to a null-terminated string,
- * removing any control character. Ex: "aaa'bb'c\'c\\" -> "aaabbc'c\"
- */
-static void copy_unquoted(char *out, const char *in, int size)
-{
- int i;
- for (i=0; i < size; i++) {
- if (in[i] == '\'')
- continue;
- else if (in[i] == '\\') {
- if (i+1 == size) {
- *out = 0;
- return;
- }
- i++;
- }
- *out++ = in[i];
- }
- *out=0;
-}
-
-/**
* Consumes a string from *buf.
* @return a copy of the consumed string, which should be free'd after use
*/
static char *consume_string(const char **buf)
{
- const char *start;
- char *ret;
- int size;
+ char *out = av_malloc(strlen(*buf));
+ const char *in = *buf;
+ char *ret = out;
consume_whitespace(buf);
- if (!(**buf))
- return av_mallocz(1);
-
- start = *buf;
-
- while(1) {
- *buf += strcspn(*buf, " ()=,'\\");
- if (**buf == '\\')
- *buf+=2;
- else
+ do{
+ char c = *in++;
+ switch (c) {
+ case '\\':
+ *out++= *in++;
break;
- }
-
- if (**buf == '\'') {
- const char *p = *buf;
- do {
- p++;
- p = strchr(p, '\'');
- } while (p && p[-1] == '\\');
- if (p)
- *buf = p + 1;
- else
- *buf += strlen(*buf); // Move the pointer to the null end byte
- }
-
- size = *buf - start + 1;
- ret = av_malloc(size);
- copy_unquoted(ret, start, size-1);
+ case '\'':
+ while(*in && *in != '\'')
+ *out++= *in++;
+ if(*in) in++;
+ break;
+ case 0:
+ case ')':
+ case '(':
+ case '=':
+ case ',':
+ *out++= 0;
+ break;
+ default:
+ *out++= c;
+ }
+ } while(out[-1]);
+ *buf = in-1;
return ret;
}