mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
json: encode_pretty (p. 1)
This commit is contained in:
@ -7,6 +7,7 @@ module json
|
||||
#flag @VROOT/thirdparty/cJSON/cJSON.o
|
||||
#include "cJSON.h"
|
||||
#define js_get(object, key) cJSON_GetObjectItemCaseSensitive((object), (key))
|
||||
|
||||
struct C.cJSON {
|
||||
valueint int
|
||||
valuedouble f32
|
||||
@ -23,6 +24,11 @@ pub fn encode(x voidptr) string {
|
||||
return ''
|
||||
}
|
||||
|
||||
pub fn encode_pretty(x voidptr) string {
|
||||
// compiler implementation
|
||||
return ''
|
||||
}
|
||||
|
||||
fn decode_int(root &C.cJSON) int {
|
||||
if isnil(root) {
|
||||
return 0
|
||||
@ -107,21 +113,17 @@ fn decode_string(root &C.cJSON) string {
|
||||
|
||||
fn C.cJSON_IsTrue(voidptr) bool
|
||||
|
||||
|
||||
fn C.cJSON_CreateNumber(int) &C.cJSON
|
||||
|
||||
|
||||
fn C.cJSON_CreateBool(bool) &C.cJSON
|
||||
|
||||
|
||||
fn C.cJSON_CreateString(charptr) &C.cJSON
|
||||
|
||||
|
||||
fn C.cJSON_Parse(charptr) &C.cJSON
|
||||
|
||||
|
||||
fn C.cJSON_PrintUnformatted(voidptr) byteptr
|
||||
|
||||
fn C.cJSON_Print(voidptr) byteptr
|
||||
|
||||
fn decode_bool(root &C.cJSON) bool {
|
||||
if isnil(root) {
|
||||
@ -178,6 +180,7 @@ fn encode_bool(val bool) &C.cJSON {
|
||||
fn encode_string(val string) &C.cJSON {
|
||||
return C.cJSON_CreateString(val.str)
|
||||
}
|
||||
|
||||
// ///////////////////////
|
||||
// user := decode_User(json_parse(js_string_var))
|
||||
fn json_parse(s string) &C.cJSON {
|
||||
@ -190,6 +193,11 @@ fn json_print(json &C.cJSON) string {
|
||||
return unsafe { tos(s, C.strlen(s)) }
|
||||
}
|
||||
|
||||
fn json_print_pretty(json &C.cJSON) string {
|
||||
s := C.cJSON_Print(json)
|
||||
return unsafe { tos(s, C.strlen(s)) }
|
||||
}
|
||||
|
||||
// / cjson wrappers
|
||||
// fn json_array_for_each(val, root &C.cJSON) {
|
||||
// #cJSON_ArrayForEach (val ,root)
|
||||
|
Reference in New Issue
Block a user