mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
[]byte.clone()
This commit is contained in:
parent
d8b83bdd00
commit
20a885ff1d
2 changed files with 16 additions and 0 deletions
8
vlib/builtin/byte_test.v
Normal file
8
vlib/builtin/byte_test.v
Normal 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
|
||||
}
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue