[1/6] avprobe: Support printing strings with empty keys

Message ID 20180404152939.55513-1-vittorio.giovara@gmail.com
State Committed
Commit f821b2ea276ebe7ecd854fbef9e3acd691bbf074
Headers show
Series
  • [1/6] avprobe: Support printing strings with empty keys
Related show

Commit Message

Vittorio Giovara April 4, 2018, 3:29 p.m.
---
 avtools/avprobe.c | 38 ++++++++++++++++++++++++++------------
 1 file changed, 26 insertions(+), 12 deletions(-)

Comments

Luca Barbato April 4, 2018, 3:53 p.m. | #1
On 04/04/2018 17:29, Vittorio Giovara wrote:
> ---
>  avtools/avprobe.c | 38 ++++++++++++++++++++++++++------------
>  1 file changed, 26 insertions(+), 12 deletions(-)
> 
> diff --git a/avtools/avprobe.c b/avtools/avprobe.c
> index a9ca1934ca..d6809042f7 100644
> --- a/avtools/avprobe.c
> +++ b/avtools/avprobe.c
> @@ -235,10 +235,14 @@ static void ini_print_integer(const char *key, int64_t value)
>  
>  static void ini_print_string(const char *key, const char *value)
>  {
> -    ini_escape_print(key);
> -    avio_printf(probe_out, "=");
> -    ini_escape_print(value);
> -    avio_w8(probe_out, '\n');
> +    if (key) {
> +        ini_escape_print(key);
> +        avio_printf(probe_out, "=%s\n", value);
> +    } else {
> +        if (octx.prefix[octx.level -1].nb_elems)
> +            avio_printf(probe_out, ",");
> +        avio_printf(probe_out, "%s", value);
> +    }
>  }
>  
>  /*
> @@ -329,14 +333,24 @@ static void json_escape_print(const char *s)
>  
>  static void json_print_string(const char *key, const char *value)
>  {
> -    if (octx.prefix[octx.level -1].nb_elems)
> -        avio_printf(probe_out, ",\n");
> -    AVP_INDENT();
> -    avio_w8(probe_out, '\"');
> -    json_escape_print(key);
> -    avio_printf(probe_out, "\" : \"");
> -    json_escape_print(value);
> -    avio_w8(probe_out, '\"');
> +    if (key) {
> +        if (octx.prefix[octx.level -1].nb_elems)
> +            avio_printf(probe_out, ",\n");
> +        AVP_INDENT();
> +        avio_w8(probe_out, '\"');
> +        json_escape_print(key);
> +        avio_printf(probe_out, "\" : \"");
> +        json_escape_print(value);
> +        avio_w8(probe_out, '\"');
> +    } else {
> +        if (octx.prefix[octx.level -1].nb_elems)
> +            avio_printf(probe_out, ", ");
> +        else
> +            AVP_INDENT();
> +        avio_w8(probe_out, '\"');
> +        json_escape_print(value);
> +        avio_w8(probe_out, '\"');
> +    }
>  }
>  
>  /*
> 

Ok.

Patch

diff --git a/avtools/avprobe.c b/avtools/avprobe.c
index a9ca1934ca..d6809042f7 100644
--- a/avtools/avprobe.c
+++ b/avtools/avprobe.c
@@ -235,10 +235,14 @@  static void ini_print_integer(const char *key, int64_t value)
 
 static void ini_print_string(const char *key, const char *value)
 {
-    ini_escape_print(key);
-    avio_printf(probe_out, "=");
-    ini_escape_print(value);
-    avio_w8(probe_out, '\n');
+    if (key) {
+        ini_escape_print(key);
+        avio_printf(probe_out, "=%s\n", value);
+    } else {
+        if (octx.prefix[octx.level -1].nb_elems)
+            avio_printf(probe_out, ",");
+        avio_printf(probe_out, "%s", value);
+    }
 }
 
 /*
@@ -329,14 +333,24 @@  static void json_escape_print(const char *s)
 
 static void json_print_string(const char *key, const char *value)
 {
-    if (octx.prefix[octx.level -1].nb_elems)
-        avio_printf(probe_out, ",\n");
-    AVP_INDENT();
-    avio_w8(probe_out, '\"');
-    json_escape_print(key);
-    avio_printf(probe_out, "\" : \"");
-    json_escape_print(value);
-    avio_w8(probe_out, '\"');
+    if (key) {
+        if (octx.prefix[octx.level -1].nb_elems)
+            avio_printf(probe_out, ",\n");
+        AVP_INDENT();
+        avio_w8(probe_out, '\"');
+        json_escape_print(key);
+        avio_printf(probe_out, "\" : \"");
+        json_escape_print(value);
+        avio_w8(probe_out, '\"');
+    } else {
+        if (octx.prefix[octx.level -1].nb_elems)
+            avio_printf(probe_out, ", ");
+        else
+            AVP_INDENT();
+        avio_w8(probe_out, '\"');
+        json_escape_print(value);
+        avio_w8(probe_out, '\"');
+    }
 }
 
 /*