mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +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
|
@ -71,7 +71,7 @@ pub fn (s string) split(dot string) []string {
|
|||
pub fn (s string) bytes() []byte {
|
||||
sep := ''
|
||||
mut arr := s.str.split(sep.str).map(it.charCodeAt(0))
|
||||
#arr = new array(arr)
|
||||
#arr = new array(new array_buffer({arr,index_start: new int(0),len: new int(arr.length)}))
|
||||
|
||||
return arr
|
||||
}
|
||||
|
@ -735,11 +735,21 @@ pub fn (s string) index_after(p string, start int) int {
|
|||
|
||||
pub fn (s string) split_into_lines() []string {
|
||||
mut res := []string{}
|
||||
#let i = 0
|
||||
#s.str.split('\n').forEach((str) => {
|
||||
#res.arr[i] = new string(str);
|
||||
#})
|
||||
|
||||
if s.len == 0 {
|
||||
return res
|
||||
}
|
||||
mut start := 0
|
||||
mut end := 0
|
||||
for i := 0; i < s.len; i++ {
|
||||
if s[i] == 10 {
|
||||
end = if i > 0 && s[i - 1] == 13 { i - 1 } else { i }
|
||||
res << if start == end { '' } else { s[start..end] }
|
||||
start = i + 1
|
||||
}
|
||||
}
|
||||
if start < s.len {
|
||||
res << s[start..]
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue