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:
parent
562f24336d
commit
ea781a557f
@ -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)')
|
||||||
|
Loading…
Reference in New Issue
Block a user