From 72ae12877ef9b30b9ca4e1c92c23e7e1a486ef58 Mon Sep 17 00:00:00 2001 From: joe-conigliaro Date: Sat, 5 Oct 2019 18:07:10 +1000 Subject: [PATCH] remvoe dupe in main & fix js string.builder (#2233) --- compiler/main.v | 3 --- vlib/strings/builder_js.v | 14 +++++++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/compiler/main.v b/compiler/main.v index 8f802e1c69..e35972a655 100644 --- a/compiler/main.v +++ b/compiler/main.v @@ -557,9 +557,6 @@ fn (v &V) v_files_from_dir(dir string) []string { if file.ends_with('_mac.v') && v.os != .mac { continue } - if file.ends_with('_js.v') && v.os != .js { - continue - } if file.ends_with('_nix.v') && (v.os == .windows || v.os == .msvc) { continue } diff --git a/vlib/strings/builder_js.v b/vlib/strings/builder_js.v index 8b7413b4ff..9861a2f1dc 100644 --- a/vlib/strings/builder_js.v +++ b/vlib/strings/builder_js.v @@ -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) }