mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix []u8 string representation (#15432)
This commit is contained in:
parent
3aad5e2a8d
commit
3bc01d696d
@ -541,10 +541,7 @@ fn (mut g Gen) gen_str_for_array(info ast.Array, styp string, str_fn_name string
|
|||||||
field_styp := g.typ(typ)
|
field_styp := g.typ(typ)
|
||||||
is_elem_ptr := typ.is_ptr()
|
is_elem_ptr := typ.is_ptr()
|
||||||
sym_has_str_method, str_method_expects_ptr, _ := sym.str_method_info()
|
sym_has_str_method, str_method_expects_ptr, _ := sym.str_method_info()
|
||||||
mut elem_str_fn_name := g.get_str_fn(typ)
|
elem_str_fn_name := g.get_str_fn(typ)
|
||||||
if sym.kind == .u8 {
|
|
||||||
elem_str_fn_name = elem_str_fn_name + '_escaped'
|
|
||||||
}
|
|
||||||
|
|
||||||
g.definitions.writeln('static string ${str_fn_name}($styp a); // auto')
|
g.definitions.writeln('static string ${str_fn_name}($styp a); // auto')
|
||||||
g.auto_str_funcs.writeln('static string ${str_fn_name}($styp a) { return indent_${str_fn_name}(a, 0);}')
|
g.auto_str_funcs.writeln('static string ${str_fn_name}($styp a) { return indent_${str_fn_name}(a, 0);}')
|
||||||
|
@ -19,7 +19,7 @@ fn test_array_to_string_conversion() {
|
|||||||
assert e.str() == '[1, 2, 3]'
|
assert e.str() == '[1, 2, 3]'
|
||||||
|
|
||||||
f := [u8(66), 32, 126, 10, 13, 5, 18, 127, 255]
|
f := [u8(66), 32, 126, 10, 13, 5, 18, 127, 255]
|
||||||
assert f.str() == '[B, , ~, `\\n`, `\\r`, 0x05, 0x12, 0x7f, 0xff]'
|
assert f.str() == '[66, 32, 126, 10, 13, 5, 18, 127, 255]'
|
||||||
|
|
||||||
// https://github.com/vlang/v/issues/8036
|
// https://github.com/vlang/v/issues/8036
|
||||||
g := array_array_array<int>(2, 2)
|
g := array_array_array<int>(2, 2)
|
||||||
|
@ -15,10 +15,10 @@ fn test_fn_with_array_of_aliases_argument() {
|
|||||||
|
|
||||||
s1 := show_array_of_u8(a)
|
s1 := show_array_of_u8(a)
|
||||||
println(s1)
|
println(s1)
|
||||||
assert s1 == '[0x01, 0x02, 0x03]'
|
assert s1 == '[1, 2, 3]'
|
||||||
|
|
||||||
foo := Foo{}
|
foo := Foo{}
|
||||||
s2 := foo.show_array_of_u8(a)
|
s2 := foo.show_array_of_u8(a)
|
||||||
println(s2)
|
println(s2)
|
||||||
assert s2 == '[0x01, 0x02, 0x03]'
|
assert s2 == '[1, 2, 3]'
|
||||||
}
|
}
|
||||||
|
@ -22,5 +22,5 @@ fn hex_to_bytes(s string) ?[]u8 {
|
|||||||
fn test_multiple_matchs_in_one_expr() {
|
fn test_multiple_matchs_in_one_expr() {
|
||||||
ret := hex_to_bytes('FFFF') or { 'error'.bytes() }
|
ret := hex_to_bytes('FFFF') or { 'error'.bytes() }
|
||||||
println(ret)
|
println(ret)
|
||||||
assert '$ret' == '[U, U]'
|
assert '$ret' == '[85, 85]'
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import compress.zlib as z
|
import compress.zlib as z
|
||||||
z.compress('hello world'.bytes())?
|
z.compress('hello world'.bytes())?
|
||||||
===output===
|
===output===
|
||||||
[x, 0x01, 0x01, `/v`, `/0`, 0xf4, 0xff, h, e, l, l, o, , w, o, r, l, d, 0x1a, `/v`, 0x04, ]]
|
[120, 1, 1, 11, 0, 244, 255, 104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 26, 11, 4, 93]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user