From 92d291674e5a12c7eedd314ffc4cf955d575cbea Mon Sep 17 00:00:00 2001 From: Joshua Allen Date: Sat, 6 May 2017 22:05:32 -0400 Subject: add function to parse array of floats from json --- redist/json_helpers.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'redist/json_helpers.c') diff --git a/redist/json_helpers.c b/redist/json_helpers.c index c52301d..af7ddda 100644 --- a/redist/json_helpers.c +++ b/redist/json_helpers.c @@ -216,3 +216,32 @@ void json_load_file(const char* path) { free(JSON_STRING); } +int parse_float_array(char* str, jsmntok_t* token, FLT** f, uint8_t count) { + uint16_t i = 0; + + if (count==0) return 0; + + if (*f!=NULL) free(*f); + *f = malloc(sizeof(FLT) * count); + + for(i=0;iend; + char* s = str+token->start; + + #ifdef USE_DOUBLE + (*f)[i] = strtod(s, &end); + #else + (*f)[i] = strtof(s, &end); + #endif + + if (s == end) { + free(*f); + *f=NULL; + return 0; //not a float + } + token++; + } + + + return count; +} \ No newline at end of file -- cgit v1.2.3