[FFmpeg-devel] [PATCH] lavf/segment: Simplify CSV field quoting code

Stefano Sabatini stefasab at gmail.com
Mon Sep 10 11:05:05 CEST 2012


On date Sunday 2012-09-09 21:54:04 +0200, Alexander Strasser encoded:
> Should also be faster (though I doubt that hardly
> ever matters for the usage here).
> 
> Signed-off-by: Alexander Strasser <eclipse7 at gmx.net>
> ---
> 
>   I do not see any downsides to the previous code, but it is more
> compact. The idea to do it this way came to my mind after re-reading
> Stefano's code on -cvslog.
> 
>   If I didn't mess up; this idiom could be used in other places
> where one wants to find out if a zero terminated string contains
> one or more characters from a set of ASCII characters.
> 
>   I have no particular ambition with this patch besides pointing
> out a different way to do it. If I hear no comments I will drop
> this patch eventually.
> 
>   In this instance the double negation isn't really necessary
> but I found it to be more clear/readable.
> 
> 
>  libavformat/segment.c | 9 ++-------
>  1 file changed, 2 insertions(+), 7 deletions(-)
> 
> diff --git a/libavformat/segment.c b/libavformat/segment.c
> index 5ae15bd..a5bed1b 100644
> --- a/libavformat/segment.c
> +++ b/libavformat/segment.c
> @@ -73,14 +73,9 @@ typedef struct {
>  static void print_csv_escaped_str(AVIOContext *ctx, const char *str)
>  {
>      const char *p;
> -    int quote = 0;
> +    int quote;
>  
> -    /* check if input needs quoting */
> -    for (p = str; *p; p++)
> -        if (strchr("\",\n\r", *p)) {
> -            quote = 1;
> -            break;
> -        }

> +    quote = !!str[strcspn(str, "\",\n\r")];

Can be merged with declaration.

Patch looks OK, maybe add a comment like:

// check if string contains special characters
int quote = ...;

Thanks.
-- 
FFmpeg = Fierce and Fanciful Muttering Prodigious Enlightening Guide


More information about the ffmpeg-devel mailing list