Refactor json_pack()

* Implement a "scanner" that reads the format string, maintaining state

* Split json_vnpack() to three separate functions for packing objects,
  arrays and simple values. This makes it more clear what is being
  packed, and the object and array structures become more evident.

* Make the skipping of ignored character simpler, i.e. skip ':' and
  ',' independent of their context

This patch shaves around 80 lines of code from the original
implementation.
This commit is contained in:
Petri Lehtinen
2011-01-23 21:14:19 +02:00
parent 53383860e8
commit 7f3018a4fb
4 changed files with 176 additions and 253 deletions

View File

@@ -1,6 +1,4 @@
#include <string.h>
#include <stdarg.h>
#include "jansson_private.h"
void jsonp_error_init(json_error_t *error, const char *source)
@@ -21,6 +19,14 @@ void jsonp_error_set(json_error_t *error, int line, int column,
{
va_list ap;
va_start(ap, msg);
jsonp_error_vset(error, line, column, msg, ap);
va_end(ap);
}
void jsonp_error_vset(json_error_t *error, int line, int column,
const char *msg, va_list ap)
{
if(!error)
return;
@@ -32,7 +38,5 @@ void jsonp_error_set(json_error_t *error, int line, int column,
error->line = line;
error->column = column;
va_start(ap, msg);
vsnprintf(error->text, JSON_ERROR_TEXT_LENGTH, msg, ap);
va_end(ap);
}