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

remvoe dupe in main & fix js string.builder (#2233)

This commit is contained in:
joe-conigliaro
2019-10-05 18:07:10 +10:00
committed by GitHub
parent a62dec2053
commit 72ae12877e
2 changed files with 13 additions and 4 deletions

View File

@ -5,27 +5,39 @@
module strings
struct Builder {
mut:
buf []byte
pub:
len int
}
pub fn new_builder(initial_size int) Builder {
return Builder {
buf: _make(0, initial_size, sizeof(byte))
}
}
pub fn (b mut Builder) write(s string) {
b.buf._push_many(s.str, s.len)
//b.buf << []byte(s) // TODO
b.len += s.len
}
pub fn (b mut Builder) writeln(s string) {
b.buf._push_many(s.str, s.len)
//b.buf << []byte(s) // TODO
b.buf << `\n`
b.len += s.len + 1
}
pub fn (b Builder) str() string {
return ''
return string(b.buf, b.len)
}
pub fn (b mut Builder) cut(n int) {
b.len -= n
}
pub fn (b mut Builder) free() {
free(b.buf.data)
}