diff options
author | Stefano Sabatini <stefasab@gmail.com> | 2012-12-16 15:17:23 +0400 |
---|---|---|
committer | Stefano Sabatini <stefasab@gmail.com> | 2013-03-07 04:12:04 +0400 |
commit | 9767ec6b865c35f68cb6642fefeacc009f17e638 (patch) | |
tree | 6a887bbb054464e240e17d3d185ba0b2e6b63290 /libavutil/avstring.c | |
parent | 38d40ac18a3855620852e6552114caeb413497eb (diff) |
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.
Diffstat (limited to 'libavutil/avstring.c')
-rw-r--r-- | libavutil/avstring.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/libavutil/avstring.c b/libavutil/avstring.c index 9ad1e12711..45f8d78172 100644 --- a/libavutil/avstring.c +++ b/libavutil/avstring.c @@ -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) |