mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
builtin: x.vstring() instead of string(x) (#6102)
This commit is contained in:
@ -38,7 +38,7 @@ pub fn (mut b Builder) writeln(s string) {
|
||||
}
|
||||
|
||||
pub fn (b Builder) str() string {
|
||||
return string(b.buf, b.len)
|
||||
return unsafe { byteptr(b.buf.data).vstring_with_len(b.len) }
|
||||
}
|
||||
|
||||
pub fn (mut b Builder) cut(n int) {
|
||||
|
@ -116,7 +116,7 @@ pub fn (mut b Builder) str() string {
|
||||
'If you want to reuse a builder, call b.free() first.')
|
||||
}
|
||||
b.buf << `\0`
|
||||
s := string(b.buf,b.len)
|
||||
s := tos(b.buf.data, b.len)
|
||||
bis := b.initial_size
|
||||
//free(b.buf.data)
|
||||
b.buf = []byte{cap: bis}
|
||||
|
@ -10,7 +10,7 @@ pub fn repeat(c byte, n int) string {
|
||||
C.memset( bytes, c, n )
|
||||
bytes[n] = `0`
|
||||
}
|
||||
return string( bytes, n )
|
||||
return unsafe { bytes.vstring_with_len(n) }
|
||||
}
|
||||
|
||||
// strings.repeat_string - gives you `n` repetitions of the substring `s`
|
||||
@ -34,5 +34,5 @@ pub fn repeat_string(s string, n int) string {
|
||||
unsafe {
|
||||
bytes[blen] = `0`
|
||||
}
|
||||
return string( bytes, blen )
|
||||
return unsafe { bytes.vstring_with_len(blen) }
|
||||
}
|
||||
|
@ -4,9 +4,8 @@ pub fn repeat(c byte, n int) string {
|
||||
if n <= 0 {
|
||||
return ''
|
||||
}
|
||||
mut arr := [c].repeat(n + 1)
|
||||
arr[n] = `\0`
|
||||
return string(arr,n)
|
||||
arr := [c].repeat(n)
|
||||
return arr.bytestr()
|
||||
}
|
||||
|
||||
pub fn repeat_string(s string, n int) string {
|
||||
|
Reference in New Issue
Block a user