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

[]byte.clone()

This commit is contained in:
Alexander Medvednikov 2019-07-25 18:07:16 +02:00
parent d8b83bdd00
commit 20a885ff1d
2 changed files with 16 additions and 0 deletions

8
vlib/builtin/byte_test.v Normal file
View File

@ -0,0 +1,8 @@
fn test_clone() {
a := [byte(0), 1, 2]
b := a.clone()
assert b.len == 3
assert b[0] == 0
assert b[1] == 1
assert b[2] == 2
}

View File

@ -177,3 +177,11 @@ pub fn (c byte) str() string {
return str
}
pub fn (b []byte) clone() []byte {
mut res := [byte(0); b.len]
for i := 0; i < b.len; i++ {
res[i] = b[i]
}
return res
}