[FFmpeg-devel] [PATCH 1/2] ffprobe: Simplify CSV field quoting code

Stefano Sabatini stefasab at gmail.com
Wed Sep 19 09:53:43 CEST 2012


On date Tuesday 2012-09-18 23:11:05 +0200, Alexander Strasser encoded:
> Sync with bac1b31 .
> 
> Signed-off-by: Alexander Strasser <eclipse7 at gmx.net>
> ---
> 
>   If I was correct to include the standard C header string.h here,
> it should probably also be included in the segment muxer.
> 
>  ffprobe.c | 16 ++++++----------
>  1 file changed, 6 insertions(+), 10 deletions(-)
> 
> diff --git a/ffprobe.c b/ffprobe.c
> index a0aee83..a226d0d 100644
> --- a/ffprobe.c
> +++ b/ffprobe.c
> @@ -26,6 +26,8 @@
>  #include "config.h"
>  #include "version.h"
>  
> +#include <string.h>
> +
>  #include "libavformat/avformat.h"
>  #include "libavcodec/avcodec.h"
>  #include "libavutil/avstring.h"
> @@ -564,21 +566,15 @@ static const char *c_escape_str(AVBPrint *dst, const char *src, const char sep,
>   */
>  static const char *csv_escape_str(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
>  {
> -    const char *p;
> -    int quote = 0;
> -
> -    /* check if input needs quoting */
> -    for (p = src; *p; p++)
> -        if (*p == '"' || *p == sep || *p == '\n' || *p == '\r')
> -            quote = 1;
> +    int quote = !!src[strcspn(src, "\",\n\r")];
>  
>      if (quote)
>          av_bprint_chars(dst, '\"', 1);
>  
> -    for (p = src; *p; p++) {
> -        if (*p == '"')
> +    for (; *src; src++) {
> +        if (*src == '"')
>              av_bprint_chars(dst, '\"', 1);
> -        av_bprint_chars(dst, *p, 1);
> +        av_bprint_chars(dst, *src, 1);
>      }
>      if (quote)
>          av_bprint_chars(dst, '\"', 1);

Should be fine if tested, thanks.
-- 
FFmpeg = Frenzy and Fundamental Marvellous Peaceful Empowered Guide


More information about the ffmpeg-devel mailing list