mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen:gen_str_for_array
This commit is contained in:
@ -377,68 +377,6 @@ 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 {
|
||||
mut sb := strings.new_builder(a.len * 13)
|
||||
sb.write('[')
|
||||
for i in 0..a.len {
|
||||
val := a[i].str()
|
||||
sb.write(val)
|
||||
//println('"$val"')
|
||||
if a[i] != 0 {
|
||||
val.free()
|
||||
}
|
||||
if i < a.len - 1 {
|
||||
sb.write(', ')
|
||||
}
|
||||
}
|
||||
sb.write(']')
|
||||
return sb.str()
|
||||
}
|
||||
|
||||
// []bool.str returns a string representation of the array of bools
|
||||
// => '[true, true, false]'
|
||||
pub fn (a []bool) str() string {
|
||||
mut sb := strings.new_builder(a.len * 3)
|
||||
sb.write('[')
|
||||
for i in 0..a.len {
|
||||
val := a[i]
|
||||
if val {
|
||||
sb.write('true')
|
||||
}
|
||||
else {
|
||||
sb.write('false')
|
||||
}
|
||||
if i < a.len - 1 {
|
||||
sb.write(', ')
|
||||
}
|
||||
}
|
||||
sb.write(']')
|
||||
return sb.str()
|
||||
}
|
||||
|
||||
// []byte.hex returns a string with the hexadecimal representation
|
||||
// of the byte elements of the array
|
||||
pub fn (b []byte) hex() string {
|
||||
|
Reference in New Issue
Block a user