mirror of
https://github.com/vlang/v.git
synced 2025-09-14 15:02:33 +03:00
js: add more tests to builtin/js and implement more builtin functions (#12049)
This commit is contained in:
parent
129c81f34d
commit
9145cd66ec
10 changed files with 2384 additions and 18 deletions
|
@ -1,5 +1,26 @@
|
|||
module builtin
|
||||
|
||||
pub fn (i i8) str() string {
|
||||
mut res := ''
|
||||
#res.str = i.val.toString()
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
pub fn (i i16) str() string {
|
||||
mut res := ''
|
||||
#res.str = i.val.toString()
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
pub fn (i u16) str() string {
|
||||
mut res := ''
|
||||
#res.str = i.val.toString()
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
pub fn (i int) str() string {
|
||||
mut res := ''
|
||||
#res = new string( i )
|
||||
|
@ -48,3 +69,82 @@ pub fn (i int_literal) str() string {
|
|||
|
||||
return res
|
||||
}
|
||||
|
||||
pub fn (x u64) hex() string {
|
||||
res := ''
|
||||
#res.str = x.val.toString(16)
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
pub fn (x i64) hex() string {
|
||||
res := ''
|
||||
#res.str = x.val.toString(16)
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
pub fn (x u32) hex() string {
|
||||
res := ''
|
||||
#res.str = x.val.toString(16)
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
pub fn (x u16) hex() string {
|
||||
res := ''
|
||||
#res.str = x.val.toString(16)
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
pub fn (x i8) hex() string {
|
||||
res := ''
|
||||
#res.str = x.val.toString(16)
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
pub fn (x i16) hex() string {
|
||||
res := ''
|
||||
#res.str = x.val.toString(16)
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
pub fn (x int) hex() string {
|
||||
res := ''
|
||||
#res.str = x.val.toString(16)
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
pub fn (x int_literal) hex() string {
|
||||
res := ''
|
||||
#res.str = x.val.toString(16)
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
pub fn (x byte) hex() string {
|
||||
res := ''
|
||||
#res.str = x.val.toString(16)
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
// hex returns a string with the hexadecimal representation
|
||||
// of the byte elements of the array.
|
||||
pub fn (b []byte) hex() string {
|
||||
mut hex := ''
|
||||
for i in b {
|
||||
mut z := i
|
||||
z = z
|
||||
#let n0 = i.val >> 4
|
||||
#hex.str += n0 < 10 ? String.fromCharCode(n0) : String.fromCharCode(n0 + 87)
|
||||
|
||||
#let n1 = i.val & 0xF
|
||||
#hex.str += n1 < 10 ? String.fromCharCode(n1) : String.fromCharCode(n1 + 87)
|
||||
}
|
||||
return hex
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue