lavu: add escape API
The escape API will be useful to perform escaping programmatically, which is required when crafting argument strings, and will be used for context printing as well. This is based on the ffescape tool code, with a few extensions and fixes.
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#include "common.h"
|
||||
#include "mem.h"
|
||||
#include "avstring.h"
|
||||
#include "bprint.h"
|
||||
|
||||
int av_strstart(const char *str, const char *pfx, const char **ptr)
|
||||
{
|
||||
@@ -267,6 +268,23 @@ const char *av_dirname(char *path)
|
||||
return path;
|
||||
}
|
||||
|
||||
int av_escape(char **dst, const char *src, const char *special_chars,
|
||||
enum AVEscapeMode mode, int flags)
|
||||
{
|
||||
AVBPrint dstbuf;
|
||||
|
||||
av_bprint_init(&dstbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
|
||||
av_bprint_escape(&dstbuf, src, special_chars, mode, flags);
|
||||
|
||||
if (!av_bprint_is_complete(&dstbuf)) {
|
||||
av_bprint_finalize(&dstbuf, NULL);
|
||||
return AVERROR(ENOMEM);
|
||||
} else {
|
||||
av_bprint_finalize(&dstbuf, dst);
|
||||
return dstbuf.len;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
|
||||
int main(void)
|
||||
|
Reference in New Issue
Block a user