mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
all: simplify return if ...
constructs to make more code compatible with -autofree
This commit is contained in:
@ -98,18 +98,27 @@ fn (mut p Parser) decode_value() ?Any {
|
||||
kind := p.tok.kind
|
||||
p.next_with_err() ?
|
||||
if p.convert_type {
|
||||
return if kind == .float { Any(tl.f64()) } else { Any(tl.i64()) }
|
||||
if kind == .float {
|
||||
return Any(tl.f64())
|
||||
}
|
||||
return Any(tl.i64())
|
||||
}
|
||||
return Any(tl)
|
||||
}
|
||||
.bool_ {
|
||||
lit := p.tok.lit.bytestr()
|
||||
p.next_with_err() ?
|
||||
return if p.convert_type { Any(lit.bool()) } else { Any(lit) }
|
||||
if p.convert_type {
|
||||
return Any(lit.bool())
|
||||
}
|
||||
return Any(lit)
|
||||
}
|
||||
.null {
|
||||
p.next_with_err() ?
|
||||
return if p.convert_type { Any(null) } else { Any('null') }
|
||||
if p.convert_type {
|
||||
return Any(null)
|
||||
}
|
||||
return Any('null')
|
||||
}
|
||||
.str_ {
|
||||
str := p.tok.lit.bytestr()
|
||||
|
@ -75,11 +75,17 @@ pub fn (f Any) json_str() string {
|
||||
}
|
||||
f32 {
|
||||
str_f32 := f.str()
|
||||
return if str_f32.ends_with('.') { '${str_f32}0' } else { str_f32 }
|
||||
if str_f32.ends_with('.') {
|
||||
return '${str_f32}0'
|
||||
}
|
||||
return str_f32
|
||||
}
|
||||
f64 {
|
||||
str_f64 := f.str()
|
||||
return if str_f64.ends_with('.') { '${str_f64}0' } else { str_f64 }
|
||||
if str_f64.ends_with('.') {
|
||||
return '${str_f64}0'
|
||||
}
|
||||
return str_f64
|
||||
}
|
||||
bool {
|
||||
return f.str()
|
||||
@ -135,10 +141,10 @@ fn json_string(s string) string {
|
||||
for char_len in char_lens {
|
||||
if char_len == 1 {
|
||||
chr := s[i]
|
||||
if chr in json2.important_escapable_chars {
|
||||
for j := 0 ; j < json2.important_escapable_chars.len; j++ {
|
||||
if chr == json2.important_escapable_chars[j] {
|
||||
sb.write_string(escaped_chars[j])
|
||||
if chr in important_escapable_chars {
|
||||
for j := 0; j < important_escapable_chars.len; j++ {
|
||||
if chr == important_escapable_chars[j] {
|
||||
sb.write_string(json2.escaped_chars[j])
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -148,7 +154,7 @@ fn json_string(s string) string {
|
||||
sb.write_b(chr)
|
||||
}
|
||||
} else {
|
||||
slice := s[i .. i + char_len]
|
||||
slice := s[i..i + char_len]
|
||||
hex_code := slice.utf32_code().hex()
|
||||
if hex_code.len == 4 {
|
||||
sb.write_string('\\u$hex_code')
|
||||
|
Reference in New Issue
Block a user