mirror of
https://github.com/johnkerl/miller.git
synced 2026-07-22 07:30:43 +00:00
JSON-input string-preserve iterate
This commit is contained in:
parent
0f3d7b23a1
commit
989eabb992
2 changed files with 27 additions and 18 deletions
|
|
@ -199,6 +199,11 @@ static int new_value(
|
|||
do { if (!state.first_pass) string[string_length] = b; ++string_length; } while (0);
|
||||
|
||||
|
||||
// xxx to do:
|
||||
// 1. Modify the data structure so sval & length are shared between boolean, integer, & double.
|
||||
// 2. Just append a byte-range (start to end pointer) rather than making repeated per-character calls
|
||||
// to these functions.
|
||||
// 3. get rid of all the pow10 stuff, and the nvals entirely.
|
||||
static inline void boolean_sval_add(json_parser_state_t* pstate, json_value_t* ptop, char b) {
|
||||
if (!pstate->first_pass) {
|
||||
ptop->u.boolean.sval[ptop->u.boolean.length++] = b;
|
||||
|
|
@ -531,6 +536,7 @@ json_value_t * json_parse(
|
|||
boolean_sval_add(&state, ptop, 'r');
|
||||
boolean_sval_add(&state, ptop, 'u');
|
||||
boolean_sval_add(&state, ptop, 'e');
|
||||
boolean_sval_end(&state, ptop);
|
||||
ptop->u.boolean.nval = 1;
|
||||
|
||||
flags |= FLAG_NEXT;
|
||||
|
|
@ -552,6 +558,7 @@ json_value_t * json_parse(
|
|||
boolean_sval_add(&state, ptop, 'l');
|
||||
boolean_sval_add(&state, ptop, 's');
|
||||
boolean_sval_add(&state, ptop, 'e');
|
||||
boolean_sval_end(&state, ptop);
|
||||
ptop->u.boolean.nval = 0;
|
||||
|
||||
flags |= FLAG_NEXT;
|
||||
|
|
@ -578,13 +585,21 @@ json_value_t * json_parse(
|
|||
|
||||
if (!state.first_pass) {
|
||||
while (isdigit(b) || b == '+' || b == '-' || b == 'e' || b == 'E' || b == '.') {
|
||||
integer_sval_add(&state, ptop, b);
|
||||
|
||||
switch (ptop->type) {
|
||||
case JSON_INTEGER:
|
||||
integer_sval_add(&state, ptop, b);
|
||||
break;
|
||||
case JSON_DOUBLE:
|
||||
dbl_sval_add(&state, ptop, b);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if ((++state.ptr) == end) {
|
||||
|
||||
switch (ptop->type) {
|
||||
case JSON_BOOLEAN:
|
||||
boolean_sval_end(&state, ptop);
|
||||
break;
|
||||
case JSON_INTEGER:
|
||||
integer_sval_end(&state, ptop);
|
||||
break;
|
||||
|
|
@ -960,7 +975,7 @@ static void json_print_non_recursive_aux(json_value_t* pvalue, int depth) {
|
|||
printf(",length=%d", pvalue->u.object.length);
|
||||
break;
|
||||
case JSON_INTEGER:
|
||||
printf(",nval=%lld", pvalue->u.integer.nval);
|
||||
printf(",nval=%lld", (long long)pvalue->u.integer.nval);
|
||||
printf(",length=%d", pvalue->u.integer.length);
|
||||
printf(",sval=\"%s\"", pvalue->u.integer.sval);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -49,9 +49,7 @@ lrec_t* validate_millerable_object(json_value_t* pjson, char* flatten_sep) {
|
|||
for (int i = 0; i < n; i++) {
|
||||
json_object_entry_t* pobject_entry = &pjson->u.object.p.values[i];
|
||||
char* key = (char*)pobject_entry->name;
|
||||
char* lrec_value = NULL;
|
||||
char* prefix = NULL;
|
||||
char free_flags = NO_FREE;
|
||||
|
||||
json_value_t* pjson_value = pobject_entry->pvalue;
|
||||
switch (pjson_value->type) {
|
||||
|
|
@ -77,24 +75,20 @@ lrec_t* validate_millerable_object(json_value_t* pjson, char* flatten_sep) {
|
|||
break;
|
||||
|
||||
case JSON_STRING:
|
||||
lrec_value = pjson_value->u.string.ptr;
|
||||
lrec_put(prec, key, lrec_value, NO_FREE);
|
||||
lrec_put(prec, key, pjson_value->u.string.ptr, NO_FREE);
|
||||
break;
|
||||
|
||||
case JSON_BOOLEAN:
|
||||
//printf("XXXB [%s]\n", pjson_value->u.boolean.sval);
|
||||
lrec_value = pjson_value->u.boolean.nval ? "true" : "false";
|
||||
lrec_put(prec, key, lrec_value, NO_FREE);
|
||||
lrec_put(prec, key, pjson_value->u.boolean.nval ? "true" : "false", NO_FREE);
|
||||
//lrec_put(prec, key, pjson_value->u.boolean.sval, NO_FREE);
|
||||
break;
|
||||
case JSON_INTEGER:
|
||||
//printf("XXXI [%s]\n", pjson_value->u.integer.sval);
|
||||
lrec_value = mlr_alloc_string_from_ll(pjson_value->u.integer.nval);
|
||||
lrec_put(prec, key, lrec_value, free_flags | FREE_ENTRY_VALUE);
|
||||
lrec_put(prec, key, mlr_alloc_string_from_ll(pjson_value->u.integer.nval), FREE_ENTRY_VALUE);
|
||||
//lrec_put(prec, key, pjson_value->u.integer.sval, NO_FREE);
|
||||
break;
|
||||
case JSON_DOUBLE:
|
||||
//printf("XXXD [%s]\n", pjson_value->u.dbl.sval);
|
||||
lrec_value = mlr_alloc_string_from_double(pjson_value->u.dbl.nval, MLR_GLOBALS.ofmt);
|
||||
lrec_put(prec, key, lrec_value, free_flags | FREE_ENTRY_VALUE);
|
||||
lrec_put(prec, key, mlr_alloc_string_from_double(pjson_value->u.dbl.nval, MLR_GLOBALS.ofmt), FREE_ENTRY_VALUE);
|
||||
//lrec_put(prec, key, pjson_value->u.dbl.sval, NO_FREE);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "%s: internal coding error detected in file %s at line %d.\n",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue