[FFmpeg-devel] [PATCH] lavu: add escape API
Stefano Sabatini
stefasab at gmail.com
Fri Dec 21 00:05:14 CET 2012
On date Sunday 2012-12-16 21:07:59 +0100, Clément Bœsch encoded:
> On Sun, Dec 16, 2012 at 12:35:52PM +0100, Stefano Sabatini wrote:
> > 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.
> >
> > TODO: bump minor, add APIchanges entry
> > ---
> > libavutil/avstring.c | 18 ++++++++++++
> > libavutil/avstring.h | 19 +++++++++++++
> > libavutil/bprint.c | 49 +++++++++++++++++++++++++++++++++
> > libavutil/bprint.h | 14 ++++++++++
> > tools/ffescape.c | 75 ++++----------------------------------------------
> > 5 files changed, 105 insertions(+), 70 deletions(-)
> >
> > diff --git a/libavutil/avstring.c b/libavutil/avstring.c
> > index f03df67..b2af333 100644
> > --- a/libavutil/avstring.c
> > +++ b/libavutil/avstring.c
> > @@ -26,6 +26,7 @@
> > #include <ctype.h>
> > #include "avstring.h"
> > #include "mem.h"
> > +#include "bprint.h"
> >
> > int av_strstart(const char *str, const char *pfx, const char **ptr)
> > {
> > @@ -211,6 +212,23 @@ int av_strncasecmp(const char *a, const char *b, size_t n)
> > return c1 - c2;
> > }
> >
> > +int av_escape(char **dst, const char *src, const char *special_chars,
> > + enum AVEscapeMode mode)
> > +{
> > + AVBPrint dstbuf;
> > +
> > + av_bprint_init(&dstbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
> > +
> > + av_bprint_escape(&dstbuf, src, special_chars, mode);
> > + if (!av_bprint_is_complete(&dstbuf)) {
> > + av_bprint_finalize(&dstbuf, NULL);
> > + return AVERROR(ENOMEM);
> > + } else {
> > + av_bprint_finalize(&dstbuf, dst);
> > + return 0;
> > + }
> > +}
> > +
> > #ifdef TEST
> >
> > #include "common.h"
> > diff --git a/libavutil/avstring.h b/libavutil/avstring.h
> > index f73d6e7..0940e2b 100644
> > --- a/libavutil/avstring.h
> > +++ b/libavutil/avstring.h
> > @@ -202,6 +202,25 @@ int av_strcasecmp(const char *a, const char *b);
> > */
> > int av_strncasecmp(const char *a, const char *b, size_t n);
> >
> > +enum AVEscapeMode {
> > + AV_ESCAPE_MODE_FULL, ///< escape each single special character and whitespace by prefixing '\'
> > + AV_ESCAPE_MODE_LAZY, ///< as AV_ESCAPE_MODE_FULL, but only escape whitespaces at the begin and at the end of the string
>
> Does this mean: "whitespaces are only escaped when found at begin & end"
> or "do not escape anything except whitespaces at begin & end"?
>
> > + AV_ESCAPE_MODE_QUOTE, ///< perform quote-escaping
> > +};
> > +
> > +#define AV_WHITESPACES " \n\t"
> > +
>
> This could be made private I believe.
[...]
> LGTM otherwise.
Updated.
Nicolas, do you want to comment?
I'll push in three days if I read no more comments.
--
FFmpeg = Frightening and Fabulous Minimalistic Pure Ecstatic Gnome
More information about the ffmpeg-devel
mailing list