From 682c6194561cc94826d3de61bb5643aba065a34d Mon Sep 17 00:00:00 2001 From: yuyi Date: Tue, 14 Apr 2020 11:55:53 +0800 Subject: [PATCH] array: fix array_byte.str error --- vlib/builtin/array.v | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/vlib/builtin/array.v b/vlib/builtin/array.v index 2505b91129..425b3bddc2 100644 --- a/vlib/builtin/array.v +++ b/vlib/builtin/array.v @@ -372,6 +372,27 @@ pub fn (a []string) str() string { return sb.str() } +// []byte.str returns a string representation of the array of bytes +// => '[`a`, `b`, `c`]' +pub fn (a []byte) str() string { + mut sb := strings.new_builder(a.len * 3) + sb.write('[') + for i in 0..a.len { + val := a[i].str() + sb.write('`') + sb.write(val) + sb.write('`') + if a[i] != 0 { + val.free() + } + if i < a.len - 1 { + sb.write(', ') + } + } + sb.write(']') + return sb.str() +} + // []int.str returns a string representation of the array of ints // => '[1, 2, 3]' pub fn (a []int) str() string {