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

strings: run v fmt (#7438)

This commit is contained in:
zakuro
2020-12-22 05:00:32 +09:00
committed by GitHub
parent fade162471
commit 6c341a77f5
8 changed files with 55 additions and 49 deletions

View File

@ -1,19 +1,18 @@
// Copyright (c) 2019-2020 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
len int
initial_size int = 1
}
pub fn new_builder(initial_size int) Builder {
return Builder {
return Builder{
buf: make(0, initial_size, sizeof(byte))
initial_size: initial_size
}
@ -26,19 +25,19 @@ pub fn (mut b Builder) write_b(data byte) {
pub fn (mut b Builder) write(s string) {
b.buf.push_many(s.str, s.len)
//b.buf << []byte(s) // TODO
// b.buf << []byte(s) // TODO
b.len += s.len
}
pub fn (mut b Builder) writeln(s string) {
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 Builder) str() string {
return unsafe { byteptr(b.buf.data).vstring_with_len(b.len) }
return unsafe {byteptr(b.buf.data).vstring_with_len(b.len)}
}
pub fn (mut b Builder) cut(n int) {