mirror of
https://github.com/vlang/v.git
synced 2025-09-14 06:52:36 +03:00
js: add initial support for runes (#12077)
This commit is contained in:
parent
115493781b
commit
b2945e916f
10 changed files with 88 additions and 25 deletions
31
vlib/builtin/js/rune.js.v
Normal file
31
vlib/builtin/js/rune.js.v
Normal 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue