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

compiler: add [..2] & [2..] support for slices

This commit is contained in:
joe-conigliaro
2019-10-27 17:36:04 +11:00
committed by Alexander Medvednikov
parent e80cf185b9
commit a075ce160e
6 changed files with 47 additions and 10 deletions

View File

@ -146,6 +146,12 @@ pub fn (s array) right(n int) array {
return s.slice(n, s.len)
}
// used internally for [2..4]
fn (s array) slice2(start, _end int, end_max bool) array {
end := if end_max { s.len } else { _end }
return s.slice(start, end)
}
pub fn (s array) slice(start, _end int) array {
mut end := _end
if start > end {