mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
json: fix #1751; support unsigned integers
This commit is contained in:
parent
f34d14d901
commit
5df31c16f7
@ -124,7 +124,8 @@ string res = tos2("");
|
|||||||
fn is_js_prim(typ string) bool {
|
fn is_js_prim(typ string) bool {
|
||||||
return typ == 'int' || typ == 'string' ||
|
return typ == 'int' || typ == 'string' ||
|
||||||
typ == 'bool' || typ == 'f32' || typ == 'f64' ||
|
typ == 'bool' || typ == 'f32' || typ == 'f64' ||
|
||||||
typ == 'i8' || typ == 'i16' || typ == 'i32' || typ == 'i64'
|
typ == 'i8' || typ == 'i16' || typ == 'i32' || typ == 'i64' ||
|
||||||
|
typ == 'u8' || typ == 'u16' || typ == 'u32' || typ == 'u64'
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (p mut Parser) decode_array(array_type string) string {
|
fn (p mut Parser) decode_array(array_type string) string {
|
||||||
|
@ -49,6 +49,34 @@ fn jsdecode_i64(root *C.cJSON) i64 {
|
|||||||
return i64(root.valuedouble) //i64 is double in C
|
return i64(root.valuedouble) //i64 is double in C
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn jsdecode_u8(root *C.cJSON) u8 {
|
||||||
|
if isnil(root) {
|
||||||
|
return u8(0)
|
||||||
|
}
|
||||||
|
return u8(root.valueint)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn jsdecode_u16(root *C.cJSON) u16 {
|
||||||
|
if isnil(root) {
|
||||||
|
return u16(0)
|
||||||
|
}
|
||||||
|
return u16(root.valueint)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn jsdecode_u32(root *C.cJSON) u32 {
|
||||||
|
if isnil(root) {
|
||||||
|
return u32(0)
|
||||||
|
}
|
||||||
|
return u32(root.valueint)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn jsdecode_u64(root *C.cJSON) u64 {
|
||||||
|
if isnil(root) {
|
||||||
|
return u64(0)
|
||||||
|
}
|
||||||
|
return u64(root.valueint)
|
||||||
|
}
|
||||||
|
|
||||||
fn jsdecode_f32(root *C.cJSON) f32 {
|
fn jsdecode_f32(root *C.cJSON) f32 {
|
||||||
if isnil(root) {
|
if isnil(root) {
|
||||||
return f32(0)
|
return f32(0)
|
||||||
@ -95,6 +123,7 @@ fn jsencode_i8(val i8) *C.cJSON {
|
|||||||
fn jsencode_i16(val i16) *C.cJSON {
|
fn jsencode_i16(val i16) *C.cJSON {
|
||||||
return C.cJSON_CreateNumber(val)
|
return C.cJSON_CreateNumber(val)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn jsencode_i32(val i32) *C.cJSON {
|
fn jsencode_i32(val i32) *C.cJSON {
|
||||||
return C.cJSON_CreateNumber(val)
|
return C.cJSON_CreateNumber(val)
|
||||||
}
|
}
|
||||||
@ -103,6 +132,22 @@ fn jsencode_i64(val i64) *C.cJSON {
|
|||||||
return C.cJSON_CreateNumber(val)
|
return C.cJSON_CreateNumber(val)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn jsencode_u8(val u8) *C.cJSON {
|
||||||
|
return C.cJSON_CreateNumber(val)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn jsencode_u16(val u16) *C.cJSON {
|
||||||
|
return C.cJSON_CreateNumber(val)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn jsencode_u32(val u32) *C.cJSON {
|
||||||
|
return C.cJSON_CreateNumber(val)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn jsencode_u64(val u64) *C.cJSON {
|
||||||
|
return C.cJSON_CreateNumber(val)
|
||||||
|
}
|
||||||
|
|
||||||
fn jsencode_f32(val f32) *C.cJSON {
|
fn jsencode_f32(val f32) *C.cJSON {
|
||||||
return C.cJSON_CreateNumber(val)
|
return C.cJSON_CreateNumber(val)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user