mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: treat the main module like any other v module
This commit is contained in:
@ -49,21 +49,26 @@ pub fn (mut b Builder) go_back(n int) {
|
||||
b.len -= n
|
||||
}
|
||||
|
||||
fn bytes2string(b []byte) string {
|
||||
mut copy := b.clone()
|
||||
copy << `\0`
|
||||
res := tos(copy.data, copy.len-1)
|
||||
return res
|
||||
}
|
||||
|
||||
pub fn (mut b Builder) cut_last(n int) string {
|
||||
buf := b.buf[b.len-n..]
|
||||
s := string(buf.clone())
|
||||
res := bytes2string( b.buf[b.len-n..] )
|
||||
b.buf.trim(b.buf.len-n)
|
||||
b.len -= n
|
||||
return s
|
||||
return res
|
||||
}
|
||||
|
||||
/*
|
||||
pub fn (mut b Builder) cut_to(pos int) string {
|
||||
buf := b.buf[pos..]
|
||||
s := string(buf.clone())
|
||||
res := bytes2string( b.buf[pos..] )
|
||||
b.buf.trim(pos)
|
||||
b.len = pos
|
||||
return s
|
||||
return res
|
||||
}
|
||||
*/
|
||||
|
||||
@ -88,8 +93,7 @@ pub fn (b &Builder) last_n(n int) string {
|
||||
if n > b.len {
|
||||
return ''
|
||||
}
|
||||
buf := b.buf[b.len-n..]
|
||||
return string(buf.clone())
|
||||
return bytes2string( b.buf[b.len-n..] )
|
||||
}
|
||||
|
||||
// buf == 'hello world'
|
||||
@ -98,10 +102,7 @@ pub fn (b &Builder) after(n int) string {
|
||||
if n >= b.len {
|
||||
return ''
|
||||
}
|
||||
buf := b.buf[n..]
|
||||
mut copy := buf.clone()
|
||||
copy << `\0`
|
||||
return string(copy)
|
||||
return bytes2string( b.buf[n..] )
|
||||
}
|
||||
|
||||
// NB: in order to avoid memleaks and additional memory copies, after a call to b.str(),
|
||||
|
Reference in New Issue
Block a user