/**
* Unescape the given string until a non escaped terminating char,
* and return the token corresponding to the unescaped string.
*
* The normal \ and ' escaping is supported. Leading and trailing
* whitespaces are removed, unless they are escaped with '\' or are
* enclosed between ''.
*
* @param buf the buffer to parse, buf will be updated to point to the
* terminating char
* @param term a 0-terminated list of terminating chars
* @return the malloced unescaped string, which must be av_freed by
* the user, NULL in case of allocation failure
*/
char *av_get_token(const char **buf, const char *term);
从*buf字符串找到第一个出现在term中的任意一个字符,将*buf进行截断,前面一部分(不包含term中的任意一个字符)通过返回值反馈,后面一部分在*buf反馈。
测试程序:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "libavutil/avstring.h"
int main(int argc, char **argv)
{
char *str = (char *)malloc(16);
char *ret = NULL;
strcpy(str, "hello world!");
ret = av_get_token(&str, argv[1]);
if (ret)
{
fprintf(stderr, "ret:%s\nstr:%s\n", ret, str);
}
else
{
fprintf(stderr, "ret is NULL.\n");
}
av_free(ret);
return 0;
}
测试结果:
[****@localhost lib]$ ./av_get_token d
ret:hello worl
str:d!
[****@localhost lib]$ ./av_get_token h
ret:
str:hello world!
[****@localhost lib]$ ./av_get_token l
ret:he
str:llo world!
[****@localhost lib]$ ./av_get_token lo
ret:he
str:llo world!
[****@localhost lib]$ ./av_get_token ow
ret:hell
str:o world!
[****@localhost lib]$ ./av_get_token aw
ret:hello
str:world!