mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
js: make vlib/v/util compile on JS backend (#12660)
This commit is contained in:
@@ -83,3 +83,9 @@ pub fn error_with_code(message string, code int) IError {
|
||||
code: code
|
||||
}
|
||||
}
|
||||
|
||||
// free allows for manually freeing memory allocated at the address `ptr`. no-op on JS backend
|
||||
[unsafe]
|
||||
pub fn free(ptr voidptr) {
|
||||
_ := ptr
|
||||
}
|
||||
|
||||
@@ -955,3 +955,23 @@ pub fn tos(jsstr JS.String) string {
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
pub fn (s string) compare(a string) int {
|
||||
min_len := if s.len < a.len { s.len } else { a.len }
|
||||
for i in 0 .. min_len {
|
||||
if s[i] < a[i] {
|
||||
return -1
|
||||
}
|
||||
if s[i] > a[i] {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
if s.len < a.len {
|
||||
return -1
|
||||
}
|
||||
if s.len > a.len {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -11,3 +11,7 @@ pub fn utf8_str_visible_length(s string) int {
|
||||
pub fn utf8_str_len(s string) int {
|
||||
return s.len
|
||||
}
|
||||
|
||||
pub fn utf8_char_len(b byte) int {
|
||||
return ((0xe5000000 >> ((b >> 3) & 0x1e)) & 3) + 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user