mirror of
https://github.com/vlang/v.git
synced 2025-09-14 06:52:36 +03:00
js: fix string.bytes codegen, readline, add tests for strings
(#12060)
This commit is contained in:
parent
e94e08475d
commit
8d1ba52d0c
14 changed files with 399 additions and 30 deletions
|
@ -45,9 +45,9 @@ fn (mut a array_buffer) set(ix int, val voidptr) {
|
|||
#array_buffer.prototype.set = function(ix,val) { array_buffer_set(this,ix,val); }
|
||||
|
||||
struct array {
|
||||
mut:
|
||||
pub mut:
|
||||
arr array_buffer
|
||||
pub:
|
||||
|
||||
len int
|
||||
cap int
|
||||
}
|
||||
|
@ -67,6 +67,14 @@ fn v_sort(mut arr array, comparator fn (voidptr, voidptr) int) {
|
|||
}
|
||||
}
|
||||
|
||||
// trim trims the array length to "index" without modifying the allocated data. If "index" is greater
|
||||
// than len nothing will be changed.
|
||||
pub fn (mut a array) trim(index int) {
|
||||
if index < a.len {
|
||||
a.len = index
|
||||
}
|
||||
}
|
||||
|
||||
#function flatIntoArray(target, source, sourceLength, targetIndex, depth) {
|
||||
#"use strict";
|
||||
#
|
||||
|
@ -368,7 +376,7 @@ pub fn (a &array) free() {
|
|||
// todo: once (a []byte) will work rewrite this
|
||||
pub fn (a array) bytestr() string {
|
||||
res := ''
|
||||
#a.arr.arr.forEach((item) => res.str += String.fromCharCode(+item))
|
||||
#for (let i = 0;i < a.arr.len.valueOf();i++) res.str += String.fromCharCode(a.arr.get(new int(i)))
|
||||
|
||||
return res
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue