Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add JEMI_UINTEGER #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions jemi.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ jemi_node_t *jemi_integer(int64_t value) {
return node;
}

jemi_node_t *jemi_uinteger(uint64_t value) {
jemi_node_t *node = jemi_alloc(JEMI_UINTEGER);
if (node) {
node->uinteger = value;
}
return node;
}

jemi_node_t *jemi_string(const char *string) {
jemi_node_t *node = jemi_alloc(JEMI_STRING);
if (node) {
Expand Down Expand Up @@ -337,6 +345,12 @@ static void emit_aux(jemi_node_t *root, jemi_writer_t writer_fn, void *arg,
emit_string(writer_fn, arg, buf);
} break;

case JEMI_UINTEGER: {
char buf[22]; // 21 digits, 1 null
snprintf(buf, sizeof(buf), "%llu", node->uinteger);
emit_string(writer_fn, arg, buf);
} break;

case JEMI_STRING: {
writer_fn('"', arg);
emit_string(writer_fn, arg, node->string);
Expand Down Expand Up @@ -380,6 +394,9 @@ static jemi_node_t *copy_node(jemi_node_t *node) {
case JEMI_INTEGER: {
copy->integer = node->integer;
}
case JEMI_UINTEGER: {
copy->uinteger = node->uinteger;
}
default: {
// no action needed
}
Expand Down
3 changes: 3 additions & 0 deletions jemi.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ typedef enum {
JEMI_ARRAY,
JEMI_FLOAT,
JEMI_INTEGER,
JEMI_UINTEGER,
JEMI_STRING,
JEMI_TRUE,
JEMI_FALSE,
Expand All @@ -69,6 +70,7 @@ typedef struct _jemi_node {
struct _jemi_node *children; // for JEMI_ARRAY or JEMI_OBJECT
double number; // for JEMI_FLOAT
int64_t integer; // for JEMI_INTEGER
uint64_t uinteger; // for JEMI_UINTEGER
const char *string; // for JEMI_STRING
};
} jemi_node_t;
Expand Down Expand Up @@ -143,6 +145,7 @@ jemi_node_t *jemi_float(double value);
* more compactly than using jemi_float().
*/
jemi_node_t *jemi_integer(int64_t value);
jemi_node_t *jemi_uinteger(uint64_t value);

/**
* @brief Create a JSON string.
Expand Down