【FFmpeg】av_get_token用法

/**
 * 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!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值