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

v orm: select

This commit is contained in:
Alexander Medvednikov
2020-06-17 00:59:33 +02:00
parent 23993d2264
commit ed58192e4c
10 changed files with 304 additions and 44 deletions

View File

@ -49,6 +49,24 @@ pub fn (mut b Builder) go_back(n int) {
b.len -= n
}
pub fn (mut b Builder) cut_last(n int) string {
buf := b.buf[b.len-n..]
s := string(buf.clone())
b.buf.trim(b.buf.len-n)
b.len -= n
return s
}
/*
pub fn (mut b Builder) cut_to(pos int) string {
buf := b.buf[pos..]
s := string(buf.clone())
b.buf.trim(pos)
b.len = pos
return s
}
*/
pub fn (mut b Builder) go_back_to(pos int) {
b.buf.trim(pos)
b.len = pos

View File

@ -8,11 +8,25 @@ fn test_sb() {
assert sb.len == 8
assert sb.str() == 'hi!hello'
assert sb.len == 0
///
sb = strings.new_builder(10)
sb.write('a')
sb.write('b')
assert sb.len == 2
assert sb.str() == 'ab'
///
sb = strings.new_builder(10)
sb.write('123456')
assert sb.cut_last(2) == '56'
assert sb.str() == '1234'
///
/*
sb = strings.new_builder(10)
sb.write('123456')
x := sb.cut_to(2)
assert x == '456'
assert sb.str() == '123'
*/
}
const (