[FFmpeg-devel] [PATCH 4/6] ffprobe: switch xml_escape_str to use av_bprint_escape; cleanup a bit

Rodger Combs rodger.combs at gmail.com
Thu Sep 10 18:12:17 CEST 2015


---
 ffprobe.c | 25 ++++++-------------------
 1 file changed, 6 insertions(+), 19 deletions(-)

diff --git a/ffprobe.c b/ffprobe.c
index 4328b61..3c097bb 100644
--- a/ffprobe.c
+++ b/ffprobe.c
@@ -1543,21 +1543,10 @@ static av_cold int xml_init(WriterContext *wctx)
     return 0;
 }
 
-static const char *xml_escape_str(AVBPrint *dst, const char *src, void *log_ctx)
+static const char *xml_escape_str(AVBPrint *dst, const char *src)
 {
-    const char *p;
-
-    for (p = src; *p; p++) {
-        switch (*p) {
-        case '&' : av_bprintf(dst, "%s", "&");  break;
-        case '<' : av_bprintf(dst, "%s", "<");   break;
-        case '>' : av_bprintf(dst, "%s", ">");   break;
-        case '"' : av_bprintf(dst, "%s", """); break;
-        case '\'': av_bprintf(dst, "%s", "'"); break;
-        default: av_bprint_chars(dst, *p, 1);
-        }
-    }
-
+    av_bprint_clear(dst);
+    av_bprint_escape(dst, src, NULL, AV_ESCAPE_MODE_XML, AV_ESCAPE_FLAG_ESCAPE_DOUBLE_QUOTE);
     return dst->str;
 }
 
@@ -1632,14 +1621,12 @@ static void xml_print_str(WriterContext *wctx, const char *key, const char *valu
 
     if (section->flags & SECTION_FLAG_HAS_VARIABLE_FIELDS) {
         XML_INDENT();
-        printf("<%s key=\"%s\"",
-               section->element_name, xml_escape_str(&buf, key, wctx));
-        av_bprint_clear(&buf);
-        printf(" value=\"%s\"/>\n", xml_escape_str(&buf, value, wctx));
+        printf("<%s key=\"%s\"", section->element_name, xml_escape_str(&buf, key));
+        printf(" value=\"%s\"/>\n", xml_escape_str(&buf, value));
     } else {
         if (wctx->nb_item[wctx->level])
             printf(" ");
-        printf("%s=\"%s\"", key, xml_escape_str(&buf, value, wctx));
+        printf("%s=\"%s\"", key, xml_escape_str(&buf, value));
     }
 
     av_bprint_finalize(&buf, NULL);
-- 
2.5.1



More information about the ffmpeg-devel mailing list