[FFmpeg-devel] [PATCH] Implement av_get_token()
Michael Niedermayer
michaelni
Fri Apr 24 15:18:45 CEST 2009
On Fri, Apr 24, 2009 at 01:32:08AM +0200, Stefano Sabatini wrote:
> Hi, as in subject.
> Maybe it should be implemented in libavutil/avstring.h, but then maybe
> is also better to wait for it to stabilize.
>
> This is the output of the test program:
>
> || -> || + ||
> |:| -> || + |:|
> | | -> || + ||
> |foo | -> |foo| + ||
> | foo| -> |foo| + ||
> | foo | -> |foo| + ||
> | foo bar : blahblah| -> |foo bar| + |: blahblah|
> |\f\o\o| -> |foo| + ||
> |'foo : \ \ ' : blahblah| -> |foo : \ \| + |: blahblah|
> |'\fo\o:': blahblah| -> |\fo\o:| + |: blahblah|
> |\'fo\o\:': foo' :blahblah| -> |'foo:: foo| + |:blahblah|
add \ at the end escaing the traiing null
and unterminated '
and escaped leading and trailing whitespace
[..]
> +char *av_get_token(const char **buf, const char *term)
> +{
> + char *out = av_malloc(strlen(*buf) + 1);
> + char *ret = out;
> + const char *p = *buf;
> + p += strspn(p, WHITESPACES);
> +
> + do {
> + char c = *p++;
> + switch (c) {
> + case '\\':
> + *out++ = *p++;
> + break;
> + case '\'':
> + while(*p && *p != '\'')
> + *out++ = *p++;
> + if(*p)
> + p++;
> + break;
> + default:
> + if (!c || strspn((p-1), term))
> + *out++ = 0;
> + else
> + *out++ = c;
> + }
> + } while(out[-1]);
> +
> + p--;
> + *buf = p;
> +
> + /* strip trailing whitespaces */
> + out--;
> + while(--out >= ret && strspn(out, WHITESPACES))
> + *out = 0;
this will remove escaped trailing whitespaces
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
it is not once nor twice but times without number that the same ideas make
their appearance in the world. -- Aristotle
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090424/8e435070/attachment.pgp>
More information about the ffmpeg-devel
mailing list