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

cgen/ast/checker: string interpolation

This commit is contained in:
Alexander Medvednikov
2020-03-21 07:01:06 +01:00
parent c21e976cad
commit 5072320803
7 changed files with 101 additions and 4 deletions

View File

@@ -55,6 +55,26 @@ pub fn (b mut Builder) writeln(s string) {
b.len += s.len + 1
}
// buf == 'hello world'
// last_n(5) returns 'world'
pub fn (b mut Builder) last_n(n int) string {
if n > b.len {
return ''
}
buf := b.buf[b.len-n..]
return string(buf.clone())
}
// buf == 'hello world'
// after(6) returns 'world'
pub fn (b mut Builder) after(n int) string {
if n >= b.len {
return ''
}
buf := b.buf[n..]
return string(buf.clone())
}
pub fn (b mut Builder) str() string {
b.buf << `\0`
return string(b.buf,b.len)