[FFmpeg-devel] [PATCH] avutil/avstring: improve av_strreplace implement
Nicolas George
george at nsup.org
Sun Apr 2 18:18:26 EEST 2017
Le tridi 13 germinal, an CCXXV, Steven Liu a écrit :
> I have implementation the av_strreplace use AVBprint, the API context now
> is:
No need to Cc mo. On the other hand, sending the function itself instead
of the diff makes it easier in this case, thanks.
Nice. Just one issue:
> char *av_strreplace(const char *str, const char *from, const char *to)
> {
> char *ret = NULL;
> const char *pstr2, *pstr = str;
> size_t tolen = strlen(to), fromlen = strlen(from);
> AVBPrint pbuf;
>
> av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
> while ((pstr2 = av_stristr(pstr, from))) {
> av_bprint_append_data(&pbuf, pstr, pstr2 - pstr);
> pstr = pstr2 + fromlen;
> av_bprint_append_data(&pbuf, to, tolen);
> }
> av_bprint_append_data(&pbuf, pstr, strlen(pstr));
> av_bprint_finalize(&pbuf, &ret);
Just before that, a check with av_bprint_is_complete() is needed because
some malloc may have failed: if it is not complete, av_bprint_finalize()
to NULL to free the buffer and return NULL.
>
> return ret;
> }
Also, did you consider extending libavutil/tests/avstring.c to cover
this new function?
Regards,
--
Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20170402/7e05272f/attachment.sig>
More information about the ffmpeg-devel
mailing list