Mercurial > vim
diff src/json.c @ 17472:dfd87ef822aa v8.1.1734
patch 8.1.1734: the evalfunc.c file is too big
commit https://github.com/vim/vim/commit/29b7d7a9aac591f920edb89241c8cde27378e50b
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Jul 22 23:03:57 2019 +0200
patch 8.1.1734: the evalfunc.c file is too big
Problem: The evalfunc.c file is too big.
Solution: Move some functions to other files.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 22 Jul 2019 23:15:05 +0200 |
parents | 6fdb0ae0cac3 |
children | f8c197962c1e |
line wrap: on
line diff
--- a/src/json.c +++ b/src/json.c @@ -1127,3 +1127,52 @@ json_find_end(js_read_T *reader, int opt return ret; } #endif + +/* + * "js_decode()" function + */ + void +f_js_decode(typval_T *argvars, typval_T *rettv) +{ + js_read_T reader; + + reader.js_buf = tv_get_string(&argvars[0]); + reader.js_fill = NULL; + reader.js_used = 0; + if (json_decode_all(&reader, rettv, JSON_JS) != OK) + emsg(_(e_invarg)); +} + +/* + * "js_encode()" function + */ + void +f_js_encode(typval_T *argvars, typval_T *rettv) +{ + rettv->v_type = VAR_STRING; + rettv->vval.v_string = json_encode(&argvars[0], JSON_JS); +} + +/* + * "json_decode()" function + */ + void +f_json_decode(typval_T *argvars, typval_T *rettv) +{ + js_read_T reader; + + reader.js_buf = tv_get_string(&argvars[0]); + reader.js_fill = NULL; + reader.js_used = 0; + json_decode_all(&reader, rettv, 0); +} + +/* + * "json_encode()" function + */ + void +f_json_encode(typval_T *argvars, typval_T *rettv) +{ + rettv->v_type = VAR_STRING; + rettv->vval.v_string = json_encode(&argvars[0], 0); +}