jsontree: add uint type

This commit is contained in:
Jeff Kent 2015-12-28 09:45:23 -06:00
parent fcc87ddce8
commit bcc7d0a1eb
3 changed files with 24 additions and 6 deletions

View file

@ -79,16 +79,11 @@ jsontree_write_string(const struct jsontree_context *js_ctx, const char *text)
}
/*---------------------------------------------------------------------------*/
void
jsontree_write_int(const struct jsontree_context *js_ctx, int value)
jsontree_write_uint(const struct jsontree_context *js_ctx, unsigned int value)
{
char buf[10];
int l;
if(value < 0) {
js_ctx->putchar('-');
value = -value;
}
l = sizeof(buf) - 1;
do {
buf[l--] = '0' + (value % 10);
@ -101,6 +96,17 @@ jsontree_write_int(const struct jsontree_context *js_ctx, int value)
}
/*---------------------------------------------------------------------------*/
void
jsontree_write_int(const struct jsontree_context *js_ctx, int value)
{
if(value < 0) {
js_ctx->putchar('-');
value = -value;
}
jsontree_write_uint(js_ctx, value);
}
/*---------------------------------------------------------------------------*/
void
jsontree_setup(struct jsontree_context *js_ctx, struct jsontree_value *root,
int (* putchar)(int))
{
@ -203,6 +209,10 @@ jsontree_print_next(struct jsontree_context *js_ctx)
jsontree_write_string(js_ctx, ((struct jsontree_string *)v)->value);
/* Default operation: back up one level! */
break;
case JSON_TYPE_UINT:
jsontree_write_uint(js_ctx, ((struct jsontree_uint *)v)->value);
/* Default operation: back up one level! */
break;
case JSON_TYPE_INT:
jsontree_write_int(js_ctx, ((struct jsontree_int *)v)->value);
/* Default operation: back up one level! */