js: add initial support for runes (#12077)

This commit is contained in:
playX 2021-10-06 10:43:49 +03:00 committed by GitHub
parent 115493781b
commit b2945e916f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 88 additions and 25 deletions

31
vlib/builtin/js/rune.js.v Normal file
View file

@ -0,0 +1,31 @@
module builtin
import strings
pub fn (ra []rune) string() string {
mut sb := strings.new_builder(ra.len)
sb.write_runes(ra)
res := sb.str()
return res
}
pub fn (c rune) repeat(count int) string {
if count < 0 {
panic('rune.repeat: count is negative: $count')
} else if count == 0 {
return ''
} else if count == 1 {
return c.str()
}
res := ''
#res.str = String.fromCharCode(c.val)
return res.repeat(count)
}
pub fn (c rune) str() string {
res := ''
#res.str = String.fromCharCode(c.val)
return res
}