|
|
@ -33,6 +33,7 @@ typedef struct { |
|
|
|
|
|
|
|
int uescape; |
|
|
|
int pretty; |
|
|
|
int use_nil; |
|
|
|
|
|
|
|
int shiftcnt; |
|
|
|
int count; |
|
|
@ -75,6 +76,7 @@ enc_new(ErlNifEnv* env) |
|
|
|
e->bytes_per_iter = DEFAULT_BYTES_PER_ITER; |
|
|
|
e->uescape = 0; |
|
|
|
e->pretty = 0; |
|
|
|
e->use_nil = 0; |
|
|
|
e->shiftcnt = 0; |
|
|
|
e->count = 0; |
|
|
|
|
|
|
@ -578,6 +580,8 @@ encode_init(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) |
|
|
|
e->uescape = 1; |
|
|
|
} else if(enif_compare(val, e->atoms->atom_pretty) == 0) { |
|
|
|
e->pretty = 1; |
|
|
|
} else if(enif_compare(val, e->atoms->atom_use_nil) == 0) { |
|
|
|
e->use_nil = 1; |
|
|
|
} else if(enif_compare(val, e->atoms->atom_force_utf8) == 0) { |
|
|
|
// Ignore, handled in Erlang |
|
|
|
} else if(get_bytes_per_iter(env, val, &(e->bytes_per_iter))) { |
|
|
@ -708,11 +712,12 @@ encode_iter(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) |
|
|
|
stack = enif_make_list_cell(env, curr, stack); |
|
|
|
stack = enif_make_list_cell(env, e->atoms->ref_array, stack); |
|
|
|
stack = enif_make_list_cell(env, item, stack); |
|
|
|
} else if(enif_compare(curr, e->atoms->atom_null) == 0) { |
|
|
|
} else if(enif_compare(curr, e->atoms->atom_null) == 0 |
|
|
|
|| (e->use_nil && enif_compare(curr, e->atoms->atom_nil) == 0)) { |
|
|
|
if(!enc_literal(e, "null", 4)) { |
|
|
|
ret = enc_error(e, "null"); |
|
|
|
goto done; |
|
|
|
} |
|
|
|
} |
|
|
|
} else if(enif_compare(curr, e->atoms->atom_true) == 0) { |
|
|
|
if(!enc_literal(e, "true", 4)) { |
|
|
|
ret = enc_error(e, "true"); |
|
|
|