--- libelwix/src/json.c 2025/08/25 13:00:37 1.13 +++ libelwix/src/json.c 2026/03/31 15:29:12 1.14 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: json.c,v 1.13 2025/08/25 13:00:37 misho Exp $ +* $Id: json.c,v 1.14 2026/03/31 15:29:12 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -12,7 +12,7 @@ terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria -Copyright 2004 - 2025 +Copyright 2004 - 2026 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -436,6 +436,34 @@ json_token2val(const char *jstr, jtok_t * __restrict t } /* + * json_token2rstr() - Return token to raw string + * + * @jstr = JSON string + * @tok = Token for convert + * @return =NULL error or !=NULL allocated str, after use should be json_freestr()|e_free() + */ +char * +json_token2rstr(const char *jstr, jtok_t * __restrict tok) +{ + char *str = NULL; + size_t len; + + if (!jstr || !tok) + return NULL; + + len = json_toklen(tok); + str = e_malloc(len + 1); + if (!str) + return NULL; + else { + memcpy(str, json_tokstr(jstr, tok), len); + str[len] = 0; + } + + return str; +} + +/* * json_token2str() - Return token to string * * @jstr = JSON string @@ -482,7 +510,7 @@ json_token2num(const char *jstr, jtok_t * __restrict t long ret = 0; char *str; - str = json_token2str(jstr, tok); + str = json_token2rstr(jstr, tok); if (!str) return 0; @@ -504,7 +532,7 @@ json_token2dbl(const char *jstr, jtok_t * __restrict t double ret = 0; char *str; - str = json_token2str(jstr, tok); + str = json_token2rstr(jstr, tok); if (!str) return 0; @@ -526,7 +554,7 @@ json_token2bool(const char *jstr, jtok_t * __restrict double ret = 0; char *str; - str = json_token2str(jstr, tok); + str = json_token2rstr(jstr, tok); if (!str) return 0;