new xj_snprintf and xj_decodef. Code from stb_sprintf was pulled in
This commit is contained in:
@@ -10,6 +10,6 @@ do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
$CC tests/test.c src/xjson.c -o test $FLAGS
|
$CC tests/test.c src/xjson.c src/xj_snprintf.c -o test $FLAGS
|
||||||
$CC examples/parse-file.c src/xjson.c -o parse-file $FLAGS
|
$CC examples/parse-file.c src/xjson.c -o parse-file $FLAGS
|
||||||
$CC examples/simple.c src/xjson.c -o simple $FLAGS
|
$CC examples/simple.c src/xjson.c -o simple $FLAGS
|
||||||
+1716
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef XJ_SNPRINTF_H
|
||||||
|
#define XJ_SNPRINTF_H
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include "xjson.h"
|
||||||
|
int xj_vsnprintf(char *buf, int count, const char *fmt, va_list va);
|
||||||
|
xj_value *xj_vdecodef(xj_alloc *alloc, xj_error *error, const char *fmt, va_list va);
|
||||||
|
xj_value *xj_decodef(xj_alloc *alloc, xj_error *error, const char *fmt, ...);
|
||||||
|
#endif
|
||||||
+1
-3
@@ -297,7 +297,7 @@ void *xj_bpalloc(xj_alloc *alloc, int size)
|
|||||||
return addr;
|
return addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void xj_preport(xj_error *error, const char *src, int off, const char *fmt, ...)
|
void xj_preport(xj_error *error, const char *src, int off, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
if(error != NULL)
|
if(error != NULL)
|
||||||
{
|
{
|
||||||
@@ -341,8 +341,6 @@ static void xj_preport(xj_error *error, const char *src, int off, const char *fm
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define xj_report(error, fmt, ...) xj_preport(error, NULL, -1, fmt, ## __VA_ARGS__)
|
|
||||||
|
|
||||||
// Create an [xj_value] that represents the [null] JSON value.
|
// Create an [xj_value] that represents the [null] JSON value.
|
||||||
xj_value *xj_value_null(xj_alloc *alloc, xj_error *error)
|
xj_value *xj_value_null(xj_alloc *alloc, xj_error *error)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
#ifndef XJSON_H
|
||||||
|
#define XJSON_H
|
||||||
|
|
||||||
typedef double xj_f64;
|
typedef double xj_f64;
|
||||||
typedef long long xj_i64;
|
typedef long long xj_i64;
|
||||||
typedef _Bool xj_bool;
|
typedef _Bool xj_bool;
|
||||||
@@ -44,6 +47,9 @@ xj_alloc *xj_alloc_new(int size, int ext);
|
|||||||
void xj_alloc_del(xj_alloc *alloc);
|
void xj_alloc_del(xj_alloc *alloc);
|
||||||
void *xj_bpalloc(xj_alloc *alloc, int size);
|
void *xj_bpalloc(xj_alloc *alloc, int size);
|
||||||
|
|
||||||
|
void xj_preport(xj_error *error, const char *src, int off, const char *fmt, ...);
|
||||||
|
#define xj_report(error, fmt, ...) xj_preport(error, NULL, -1, fmt, ## __VA_ARGS__)
|
||||||
|
|
||||||
xj_value *xj_value_null(xj_alloc *alloc, xj_error *error);
|
xj_value *xj_value_null(xj_alloc *alloc, xj_error *error);
|
||||||
xj_value *xj_value_bool(xj_bool val, xj_alloc *alloc, xj_error *error);
|
xj_value *xj_value_bool(xj_bool val, xj_alloc *alloc, xj_error *error);
|
||||||
xj_value *xj_value_int(xj_i64 val, xj_alloc *alloc, xj_error *error);
|
xj_value *xj_value_int(xj_i64 val, xj_alloc *alloc, xj_error *error);
|
||||||
@@ -58,3 +64,5 @@ char *xj_strdup(const char *str, int len, xj_alloc *alloc, xj_error *error);
|
|||||||
|
|
||||||
xj_value *xj_decode(const char *str, int len, xj_alloc *alloc, xj_error *error);
|
xj_value *xj_decode(const char *str, int len, xj_alloc *alloc, xj_error *error);
|
||||||
char *xj_encode(xj_value *value, int *len);
|
char *xj_encode(xj_value *value, int *len);
|
||||||
|
|
||||||
|
#endif /* XJSON_H */
|
||||||
+2
-1
@@ -2,7 +2,8 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include "xjson.h"
|
#include <xjson.h>
|
||||||
|
#include <xj_snprintf.h>
|
||||||
|
|
||||||
#define TEST(src_) { .line = __LINE__, .src = src_ }
|
#define TEST(src_) { .line = __LINE__, .src = src_ }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user