Commit 93b7a0f6 authored by Vitor Sessak's avatar Vitor Sessak

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
parent 5b2bb2c9
...@@ -93,69 +93,42 @@ static void consume_whitespace(const char **buf) ...@@ -93,69 +93,42 @@ static void consume_whitespace(const char **buf)
*buf += strspn(*buf, " \n\t"); *buf += strspn(*buf, " \n\t");
} }
/**
* 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. * Consumes a string from *buf.
* @return a copy of the consumed string, which should be free'd after use * @return a copy of the consumed string, which should be free'd after use
*/ */
static char *consume_string(const char **buf) static char *consume_string(const char **buf)
{ {
const char *start; char *out = av_malloc(strlen(*buf));
char *ret; const char *in = *buf;
int size; char *ret = out;
consume_whitespace(buf); consume_whitespace(buf);
if (!(**buf)) do{
return av_mallocz(1); char c = *in++;
switch (c) {
start = *buf; case '\\':
*out++= *in++;
while(1) {
*buf += strcspn(*buf, " ()=,'\\");
if (**buf == '\\')
*buf+=2;
else
break; break;
} case '\'':
while(*in && *in != '\'')
if (**buf == '\'') { *out++= *in++;
const char *p = *buf; if(*in) in++;
do { break;
p++; case 0:
p = strchr(p, '\''); case ')':
} while (p && p[-1] == '\\'); case '(':
if (p) case '=':
*buf = p + 1; case ',':
else *out++= 0;
*buf += strlen(*buf); // Move the pointer to the null end byte break;
} default:
*out++= c;
size = *buf - start + 1; }
ret = av_malloc(size); } while(out[-1]);
copy_unquoted(ret, start, size-1);
*buf = in-1;
return ret; return ret;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment