1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

v.gen.c: free indents in autogenerated .str() methods

This commit is contained in:
Delyan Angelov
2021-06-08 16:54:18 +03:00
parent d820f2da6f
commit f9c4365dc7
3 changed files with 95 additions and 88 deletions

View File

@ -17,6 +17,9 @@ pub fn new_builder(initial_size int) Builder {
// write_ptr writes `len` bytes provided byteptr to the accumulated buffer
[unsafe]
pub fn (mut b Builder) write_ptr(ptr &byte, len int) {
if len == 0 {
return
}
unsafe { b.push_many(ptr, len) }
}
@ -27,6 +30,9 @@ pub fn (mut b Builder) write_b(data byte) {
// write implements the Writer interface
pub fn (mut b Builder) write(data []byte) ?int {
if data.len == 0 {
return 0
}
b << data
return data.len
}
@ -85,7 +91,9 @@ pub fn (mut b Builder) writeln(s string) {
// for c in s {
// b.buf << c
// }
unsafe { b.push_many(s.str, s.len) }
if s.len > 0 {
unsafe { b.push_many(s.str, s.len) }
}
// b.buf << []byte(s) // TODO
b << byte(`\n`)
}