Browse Source

Handle escape chars in config

PUBLISHED_FROM=cf3873220effc2c5f26feb13143666dd39368795
Sergey Lyubka 8 years ago
parent
commit
01e6d78e8b
2 changed files with 9 additions and 2 deletions
  1. 3 2
      frozen.c
  2. 6 0
      frozen.h

+ 3 - 2
frozen.c

@@ -430,7 +430,8 @@ static int doit(struct frozen *f) {
   return parse_value(f);
   return parse_value(f);
 }
 }
 
 
-static int json_encode_string(struct json_out *out, const char *p, size_t len) {
+int json_escape(struct json_out *out, const char *p, size_t len) WEAK;
+int json_escape(struct json_out *out, const char *p, size_t len) {
   size_t i, cl, n = 0;
   size_t i, cl, n = 0;
   const char *hex_digits = "0123456789abcdef";
   const char *hex_digits = "0123456789abcdef";
   const char *specials = "btnvfr";
   const char *specials = "btnvfr";
@@ -613,7 +614,7 @@ int json_vprintf(struct json_out *out, const char *fmt, va_list xap) {
             l = strlen(p);
             l = strlen(p);
           }
           }
           len += out->printer(out, quote, 1);
           len += out->printer(out, quote, 1);
-          len += json_encode_string(out, p, l);
+          len += json_escape(out, p, l);
           len += out->printer(out, quote, 1);
           len += out->printer(out, quote, 1);
         }
         }
       } else {
       } else {

+ 6 - 0
frozen.h

@@ -207,6 +207,12 @@ int json_scanf_array_elem(const char *s, int len, const char *path, int index,
  */
  */
 int json_unescape(const char *src, int slen, char *dst, int dlen);
 int json_unescape(const char *src, int slen, char *dst, int dlen);
 
 
+/*
+ * Escape a string `str`, `str_len` into the printer `out`.
+ * Return the number of bytes printed.
+ */
+int json_escape(struct json_out *out, const char *str, size_t str_len);
+
 #ifdef __cplusplus
 #ifdef __cplusplus
 }
 }
 #endif /* __cplusplus */
 #endif /* __cplusplus */