Skip to content
Snippets Groups Projects
Commit 4f409baa authored by Vitor Sessak's avatar Vitor Sessak
Browse files

Add backslash '\' support to the parser

Commited in SoC by Vitor Sessak on 2008-03-29 16:26:47

Originally committed as revision 12744 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 398f1297
No related branches found
No related tags found
No related merge requests found
...@@ -232,19 +232,25 @@ static char consume_char(const char **buf) ...@@ -232,19 +232,25 @@ static char consume_char(const char **buf)
} }
/** /**
* remove the quotation marks from a string. Ex: "aaa'bb'cc" -> "aaabbcc" * 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 unquote(char *str) static void copy_unquoted(char *out, const char *in, int size)
{ {
char *p1, *p2; int i;
p1=p2=str; for (i=0; i < size; i++) {
while (*p1 != 0) { if (in[i] == '\'')
if (*p1 != '\'') continue;
*p2++ = *p1; else if (in[i] == '\\') {
p1++; if (i+1 == size) {
*out = 0;
return;
}
i++;
}
*out++ = in[i];
} }
*out=0;
*p2 = 0;
} }
/** /**
...@@ -264,10 +270,20 @@ static char *consume_string(const char **buf) ...@@ -264,10 +270,20 @@ static char *consume_string(const char **buf)
start = *buf; start = *buf;
*buf += strcspn(*buf, " ()=,'"); while(1) {
*buf += strcspn(*buf, " ()=,'\\");
if (**buf == '\\')
*buf+=2;
else
break;
}
if (**buf == '\'') { if (**buf == '\'') {
char *p = strchr(*buf + 1, '\''); const char *p = *buf;
do {
p++;
p = strchr(p, '\'');
} while (p && p[-1] == '\\');
if (p) if (p)
*buf = p + 1; *buf = p + 1;
else else
...@@ -276,10 +292,7 @@ static char *consume_string(const char **buf) ...@@ -276,10 +292,7 @@ static char *consume_string(const char **buf)
size = *buf - start + 1; size = *buf - start + 1;
ret = av_malloc(size); ret = av_malloc(size);
memcpy(ret, start, size - 1); copy_unquoted(ret, start, size-1);
ret[size-1] = 0;
unquote(ret);
return ret; return ret;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment