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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user