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

136 lines
2.1 KiB
V
Raw Normal View History

2020-02-03 07:00:36 +03:00
// Copyright (c) 2019-2020 Alexander Medvednikov. All rights reserved.
2019-09-14 23:48:30 +03:00
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
module builtin
import strings
2019-10-24 22:58:01 +03:00
pub struct array {
2019-09-14 23:48:30 +03:00
pub:
data voidptr
len int
cap int
element_size int
}
/*
// Private function, used by V (`nums := []int`)
fn new_array(mylen, cap, elm_size int) array {
arr := array {
len: mylen
cap: cap
element_size: elm_size
}
return arr
}
// TODO
pub fn _make(len, cap, elm_size int) array {
return new_array(len, cap, elm_size)
}
*/
2019-10-05 08:03:26 +03:00
pub fn make(len, cap, elm_size int) array {
2019-10-05 08:03:26 +03:00
return array{}
}
2019-09-14 23:48:30 +03:00
fn array_repeat(val voidptr, nr_repeats, elm_size int) array {
return val
}
2019-09-19 05:22:24 +03:00
pub fn (a array) repeat(nr_repeats int) array {
2019-09-14 23:48:30 +03:00
#return Array(a[0]).fill(nr_repeats)
return a
}
pub fn (a mut array) sort_with_compare(compare voidptr) {
}
pub fn (a mut array) insert(i int, val voidptr) {
}
pub fn (a mut array) prepend(val voidptr) {
a.insert(0, val)
}
pub fn (a mut array) delete_elm(idx int) {
}
/*
pub fn (a array) first() voidptr {
if a.len == 0 {
panic('array.first: empty array')
}
return a.data + 0
}
pub fn (a array) last() voidptr {
if a.len == 0 {
panic('array.last: empty array')
}
return a.data + (a.len - 1) * a.element_size
}
*/
pub fn (s array) left(n int) array {
if n >= s.len {
return s
}
return s.slice(0, n)
}
pub fn (s array) right(n int) array {
if n >= s.len {
return s
}
return s.slice(n, s.len)
}
pub fn (s array) slice(start, _end int) array {
return s
}
pub fn (a array) reverse() array {
return a
}
pub fn (a array) clone() array {
return a
}
pub fn (a array) free() {
}
// "[ 'a', 'b', 'c' ]"
pub fn (a []string) str() string {
mut sb := strings.new_builder(a.len * 3)
sb.write('[')
for i in 0..a.len {
2019-09-14 23:48:30 +03:00
val := a[i]
sb.write('"')
sb.write(val)
sb.write('"')
if i < a.len - 1 {
sb.write(', ')
}
}
sb.write(']')
return sb.str()
}
pub fn (b []byte) hex() string {
return 'sdf'
}
2019-10-10 01:27:16 +03:00
pub fn (arr mut array) push_many(val voidptr, size int) {
2019-09-14 23:48:30 +03:00
}
pub fn free(voidptr) {
}