Browse Source

Added json_emit_va()

Sergey Lyubka 11 years ago
parent
commit
3d1362476e
2 changed files with 15 additions and 4 deletions
  1. 12 4
      frozen.c
  2. 3 0
      frozen.h

+ 12 - 4
frozen.c

@@ -399,12 +399,10 @@ int json_emit_unquoted_str(char *buf, int buf_len, const char *str, int len) {
   return len;
   return len;
 }
 }
 
 
-int json_emit(char *s, int s_len, const char *fmt, ...) {
+int json_emit_va(char *s, int s_len, const char *fmt, va_list ap) {
   const char *end = s + s_len, *str;
   const char *end = s + s_len, *str;
   size_t len;
   size_t len;
-  va_list ap;
 
 
-  va_start(ap, fmt);
   while (*fmt != '\0') {
   while (*fmt != '\0') {
     switch (*fmt) {
     switch (*fmt) {
       case '[': case ']': case '{': case '}': case ',': case ':':
       case '[': case ']': case '{': case '}': case ',': case ':':
@@ -450,9 +448,19 @@ int json_emit(char *s, int s_len, const char *fmt, ...) {
     }
     }
     fmt++;
     fmt++;
   }
   }
-  va_end(ap);
 
 
   if (s < end) *s = '\0';
   if (s < end) *s = '\0';
 
 
   return end - s;
   return end - s;
 }
 }
+
+int json_emit(char *buf, int buf_len, const char *fmt, ...) {
+  int len;
+  va_list ap;
+
+  va_start(ap, fmt);
+  len = json_emit_va(buf, buf_len, fmt, ap);
+  va_end(ap);
+
+  return len;
+}

+ 3 - 0
frozen.h

@@ -22,6 +22,8 @@
 extern "C" {
 extern "C" {
 #endif // __cplusplus
 #endif // __cplusplus
 
 
+#include <stdarg.h>
+
 enum json_type {
 enum json_type {
   JSON_TYPE_EOF     = 0,      // End of parsed tokens marker
   JSON_TYPE_EOF     = 0,      // End of parsed tokens marker
   JSON_TYPE_STRING  = 1,
   JSON_TYPE_STRING  = 1,
@@ -58,6 +60,7 @@ int json_emit_double(char *buf, int buf_len, double value);
 int json_emit_quoted_str(char *buf, int buf_len, const char *str, int len);
 int json_emit_quoted_str(char *buf, int buf_len, const char *str, int len);
 int json_emit_unquoted_str(char *buf, int buf_len, const char *str, int len);
 int json_emit_unquoted_str(char *buf, int buf_len, const char *str, int len);
 int json_emit(char *buf, int buf_len, const char *fmt, ...);
 int json_emit(char *buf, int buf_len, const char *fmt, ...);
+int json_emit_va(char *buf, int buf_len, const char *fmt, va_list);
 
 
 #ifdef __cplusplus
 #ifdef __cplusplus
 }
 }