[FFmpeg-devel] [PATCH] lavu: add escape API

Alexander Strasser eclipse7 at gmx.net
Mon Dec 24 14:51:05 CET 2012


Nicolas George wrote:
> Le duodi 2 nivôse, an CCXXI, Stefano Sabatini a écrit :
> > > enum AVEscapeFlags {
> > > 
> > 
> > >     /**
> > >      * Use backslash escaping only.
> > >      */
> > >     AV_ESCAPE_USE_BACKSLASH = 0x1,
> > > 
> > >     /**
> > >      * Use single-quote escaping only.
> > >      */
> > >     AV_ESCAPE_USE_SINGLE_QUOTE = 0x2,
> > 
> > These two are in conflict.
> 
> They are. Conflicting flags are not uncommon.
> 
> > > 
> > >     /* note: the gap between 0x2 and 0x100 can be used to add other USE
> > >      * flags; they are not really flags, as they are exclusive */
> > > 
> > >     /**
> > >      * Consider spaces special and escape them even in the middle of the
> > >      * string.
> > >      * This is equivalent to adding the whitespace characters to the special
> > >      * characters lists, except it is guaranteed to use the exact same list
> > >      * of whitespace characters as the rest of libavutil.
> > >      */
> > >     AV_ESCAPE_WHITESPACE = 0x100,
> > > 
> > >     /**
> > >      * Escape only specified special characters.
> > >      * Without this flag, escape also any characters that may be considered
> > >      * special by av_get_token(), such as the single quote.
> > >      */
> > >     AV_ESCAPE_STRICT = 0x200,
> > 
> > Another possibility could be to have both mode and flags, even if more
> > complicated.
> 
> This is indeed another possibility, but I do not see the point of making
> things more complicated (for the API user too).
> 
> > > Should we consider making backslash an argument?
> > Where/how would be this useful?
> 
> I do not know, but I think the question deserves to be raised. Out of the
> top of my head: CSV requires quotes to be escaped by quotes, not
> backslashes.

  For CSV conforming to RFC4180 the whole field will be enclosed in double
quotes if it needs quoting and inside the field only the double quote itself
is escaped by escaping it with another double quote.

  So to produce proper quoting to be written into a CSV file we need for example
to support this: A passed string which contains a complete CSV field will be
passed in and given back we get exactly the same or the whole field enclosed
in double quotes. So we need to support something like this (each example
input/output on a single line preceded by Input/Output):

Input
123 '456
Output
123 '456

Input
123 "456
Output
"123 ""456"

The following would be wrong
Output
123 """"456

  Also the set of characters that need quoting must be specifiable by the user
as it is variable in regard to the field separator at least.

  Sorry I didn't have time to look at the proposed API yet.


  Alexander


More information about the ffmpeg-devel mailing list