--- libelwix/src/json.c 2018/03/07 12:29:28 1.4 +++ libelwix/src/json.c 2018/04/16 14:02:35 1.4.6.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: json.c,v 1.4 2018/03/07 12:29:28 misho Exp $ +* $Id: json.c,v 1.4.6.1 2018/04/16 14:02:35 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -437,7 +437,7 @@ json_token2val(const char *jstr, jtok_t * __restrict t * * @jstr = JSON string * @tok = Token for convert - * @return =NULL error or !=NULL allocated str, after use should be e_free() + * @return =NULL error or !=NULL allocated str, after use should be json_freestr()|e_free() */ char * json_token2str(const char *jstr, jtok_t * __restrict tok) @@ -478,6 +478,28 @@ json_token2num(const char *jstr, jtok_t * __restrict t return 0; ret = strtol(str, NULL, 0); + e_free(str); + return ret; +} + +/* + * json_token2dbl() - Return token to double + * + * @jstr = JSON string + * @tok = Token for convert + * @return number + */ +double +json_token2dbl(const char *jstr, jtok_t * __restrict tok) +{ + long ret = 0; + char *str; + + str = json_token2str(jstr, tok); + if (!str) + return 0; + + ret = strtod(str, NULL); e_free(str); return ret; }