mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
strings: fix for Builder.str() using b.len instead of b.buf.len
This commit is contained in:
parent
7f5c3cc1f8
commit
aff21c976b
@ -74,7 +74,7 @@ pub fn (mut b Builder) go_back(n int) {
|
|||||||
|
|
||||||
fn bytes2string(b []byte) string {
|
fn bytes2string(b []byte) string {
|
||||||
mut copy := b.clone()
|
mut copy := b.clone()
|
||||||
copy << byte(`\0`)
|
copy << byte(0)
|
||||||
return unsafe { tos(copy.data, copy.len - 1) }
|
return unsafe { tos(copy.data, copy.len - 1) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ pub fn (mut b Builder) writeln(s string) {
|
|||||||
// }
|
// }
|
||||||
unsafe { b.buf.push_many(s.str, s.len) }
|
unsafe { b.buf.push_many(s.str, s.len) }
|
||||||
// b.buf << []byte(s) // TODO
|
// b.buf << []byte(s) // TODO
|
||||||
b.buf << `\n`
|
b.buf << byte(`\n`)
|
||||||
b.len += s.len + 1
|
b.len += s.len + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,8 +139,9 @@ pub fn (b &Builder) after(n int) string {
|
|||||||
// accumulated data that was in the string builder, before the
|
// accumulated data that was in the string builder, before the
|
||||||
// .str() call.
|
// .str() call.
|
||||||
pub fn (mut b Builder) str() string {
|
pub fn (mut b Builder) str() string {
|
||||||
b.buf << `\0`
|
b.buf << byte(0)
|
||||||
s := unsafe { (&byte(memdup(b.buf.data, b.len))).vstring_with_len(b.len) }
|
bcopy := unsafe { &byte(memdup(b.buf.data, b.buf.len)) }
|
||||||
|
s := unsafe { bcopy.vstring_with_len(b.len) }
|
||||||
b.len = 0
|
b.len = 0
|
||||||
b.buf.trim(0)
|
b.buf.trim(0)
|
||||||
return s
|
return s
|
||||||
|
Loading…
Reference in New Issue
Block a user