1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
Alexander Medvednikov
2019-12-20 00:29:37 +03:00
parent b6fe2ebc0b
commit 6210984c97
54 changed files with 1757 additions and 1993 deletions

View File

@ -1,19 +1,18 @@
// Copyright (c) 2019 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
module strings
pub struct Builder {
mut:
buf []byte
buf []byte
pub mut:
len int
initial_size int = 1
len int
initial_size int=1
}
pub fn new_builder(initial_size int) Builder {
return Builder {
return Builder{
buf: make(0, initial_size, 1)
initial_size: initial_size
}
@ -31,30 +30,33 @@ pub fn (b mut Builder) write_b(data byte) {
pub fn (b mut Builder) write(s string) {
b.buf.push_many(s.str, s.len)
//for c in s {
//b.buf << c
//}
//b.buf << []byte(s) // TODO
// for c in s {
// b.buf << c
// }
// b.buf << []byte(s) // TODO
b.len += s.len
}
pub fn (b mut Builder) writeln(s string) {
//for c in s {
//b.buf << c
//}
// for c in s {
// b.buf << c
// }
b.buf.push_many(s.str, s.len)
//b.buf << []byte(s) // TODO
// b.buf << []byte(s) // TODO
b.buf << `\n`
b.len += s.len + 1
}
pub fn (b mut Builder) str() string {
b.buf << `\0`
return string(b.buf, b.len)
return string(b.buf,b.len)
}
pub fn (b mut Builder) free() {
unsafe{ free(b.buf.data) }
unsafe{
free(b.buf.data)
}
b.buf = make(0, b.initial_size, 1)
b.len = 0
}