remvoe dupe in main & fix js string.builder (#2233)
parent
a62dec2053
commit
72ae12877e
|
@ -557,9 +557,6 @@ fn (v &V) v_files_from_dir(dir string) []string {
|
||||||
if file.ends_with('_mac.v') && v.os != .mac {
|
if file.ends_with('_mac.v') && v.os != .mac {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if file.ends_with('_js.v') && v.os != .js {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if file.ends_with('_nix.v') && (v.os == .windows || v.os == .msvc) {
|
if file.ends_with('_nix.v') && (v.os == .windows || v.os == .msvc) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,27 +5,39 @@
|
||||||
module strings
|
module strings
|
||||||
|
|
||||||
struct Builder {
|
struct Builder {
|
||||||
|
mut:
|
||||||
|
buf []byte
|
||||||
pub:
|
pub:
|
||||||
len int
|
len int
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_builder(initial_size int) Builder {
|
pub fn new_builder(initial_size int) Builder {
|
||||||
return Builder {
|
return Builder {
|
||||||
|
buf: _make(0, initial_size, sizeof(byte))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (b mut Builder) write(s string) {
|
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) {
|
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 {
|
pub fn (b Builder) str() string {
|
||||||
return ''
|
return string(b.buf, b.len)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (b mut Builder) cut(n int) {
|
pub fn (b mut Builder) cut(n int) {
|
||||||
|
b.len -= n
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (b mut Builder) free() {
|
pub fn (b mut Builder) free() {
|
||||||
|
free(b.buf.data)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue