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

Alexander Strasser eclipse7 at gmx.net
Sun Sep 9 21:54:04 CEST 2012


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")];
 
     if (quote)
         avio_w8(ctx, '"');
-- 
1.7.10.2.552.gaa3bb87


More information about the ffmpeg-devel mailing list