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

array: slice_clone()

This commit is contained in:
Alexander Medvednikov 2019-12-17 01:29:40 +03:00
parent 562f24336d
commit ea781a557f

View File

@ -214,6 +214,27 @@ fn (a array) slice2(start, _end int, end_max bool) array {
// the `end` element of the original array with the length and capacity // the `end` element of the original array with the length and capacity
// set to the number of the elements in the slice. // set to the number of the elements in the slice.
fn (a array) slice(start, _end int) array { fn (a array) slice(start, _end int) array {
mut end := _end
if start > end {
panic('array.slice: invalid slice index ($start > $end)')
}
if end > a.len {
panic('array.slice: slice bounds out of range ($end >= $a.len)')
}
if start < 0 {
panic('array.slice: slice bounds out of range ($start < 0)')
}
l := end - start
res := array {
element_size: a.element_size
data: a.data + start * a.element_size
len: l
cap: l
}
return res
}
fn (a array) slice_clone(start, _end int) array {
mut end := _end mut end := _end
if start > end { if start > end {
panic('array.slice: invalid slice index ($start > $end)') panic('array.slice: invalid slice index ($start > $end)')