ffprobe: Simplify CSV field quoting code

Sync with bac1b31 .

Signed-off-by: Alexander Strasser <eclipse7@gmx.net>
release/1.0
Alexander Strasser 12 years ago
parent 7e3208a087
commit f70122dd57
  1. 16
      ffprobe.c

@ -26,6 +26,8 @@
#include "config.h" #include "config.h"
#include "version.h" #include "version.h"
#include <string.h>
#include "libavformat/avformat.h" #include "libavformat/avformat.h"
#include "libavcodec/avcodec.h" #include "libavcodec/avcodec.h"
#include "libavutil/avstring.h" #include "libavutil/avstring.h"
@ -565,21 +567,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) static const char *csv_escape_str(AVBPrint *dst, const char *src, const char sep, void *log_ctx)
{ {
const char *p; int quote = !!src[strcspn(src, "\",\n\r")];
int quote = 0;
/* check if input needs quoting */
for (p = src; *p; p++)
if (*p == '"' || *p == sep || *p == '\n' || *p == '\r')
quote = 1;
if (quote) if (quote)
av_bprint_chars(dst, '\"', 1); av_bprint_chars(dst, '\"', 1);
for (p = src; *p; p++) { for (; *src; src++) {
if (*p == '"') if (*src == '"')
av_bprint_chars(dst, '\"', 1); av_bprint_chars(dst, '\"', 1);
av_bprint_chars(dst, *p, 1); av_bprint_chars(dst, *src, 1);
} }
if (quote) if (quote)
av_bprint_chars(dst, '\"', 1); av_bprint_chars(dst, '\"', 1);

Loading…
Cancel
Save