mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
all: byte => u8
This commit is contained in:
@@ -247,7 +247,7 @@ fn _writeln_to_fd(fd int, s string) {
|
||||
}
|
||||
|
||||
[manualfree]
|
||||
fn _write_buf_to_fd(fd int, buf &byte, buf_len int) {
|
||||
fn _write_buf_to_fd(fd int, buf &u8, buf_len int) {
|
||||
if buf_len <= 0 {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ fn C.sprintf(a ...voidptr) int
|
||||
|
||||
fn C.strlen(s &char) int
|
||||
|
||||
fn C.sscanf(&byte, &byte, ...&byte) int
|
||||
fn C.sscanf(&u8, &u8, ...&u8) int
|
||||
|
||||
[trusted]
|
||||
fn C.isdigit(c int) bool
|
||||
@@ -247,11 +247,11 @@ fn C.CreateProcessW(lpApplicationName &u16, lpCommandLine &u16, lpProcessAttribu
|
||||
|
||||
fn C.ReadFile(hFile voidptr, lpBuffer voidptr, nNumberOfBytesToRead u32, lpNumberOfBytesRead C.LPDWORD, lpOverlapped voidptr) bool
|
||||
|
||||
fn C.GetFileAttributesW(lpFileName &byte) u32
|
||||
fn C.GetFileAttributesW(lpFileName &u8) u32
|
||||
|
||||
fn C.RegQueryValueEx(hKey voidptr, lpValueName &u16, lp_reserved &u32, lpType &u32, lpData &byte, lpcbData &u32) voidptr
|
||||
fn C.RegQueryValueEx(hKey voidptr, lpValueName &u16, lp_reserved &u32, lpType &u32, lpData &u8, lpcbData &u32) voidptr
|
||||
|
||||
fn C.RegQueryValueExW(hKey voidptr, lpValueName &u16, lp_reserved &u32, lpType &u32, lpData &byte, lpcbData &u32) int
|
||||
fn C.RegQueryValueExW(hKey voidptr, lpValueName &u16, lp_reserved &u32, lpType &u32, lpData &u8, lpcbData &u32) int
|
||||
|
||||
fn C.RegOpenKeyEx(hKey voidptr, lpSubKey &u16, ulOptions u32, samDesired u32, phkResult voidptr) voidptr
|
||||
|
||||
@@ -259,7 +259,7 @@ fn C.RegOpenKeyExW(hKey voidptr, lpSubKey &u16, ulOptions u32, samDesired u32, p
|
||||
|
||||
fn C.RegSetValueEx() voidptr
|
||||
|
||||
fn C.RegSetValueExW(hKey voidptr, lpValueName &u16, reserved u32, dwType u32, lpData &byte, lpcbData u32) int
|
||||
fn C.RegSetValueExW(hKey voidptr, lpValueName &u16, reserved u32, dwType u32, lpData &u8, lpcbData u32) int
|
||||
|
||||
fn C.RegCloseKey(hKey voidptr)
|
||||
|
||||
@@ -331,7 +331,7 @@ fn C.LocalFree()
|
||||
|
||||
fn C.FindFirstFileW(lpFileName &u16, lpFindFileData voidptr) voidptr
|
||||
|
||||
fn C.FindFirstFile(lpFileName &byte, lpFindFileData voidptr) voidptr
|
||||
fn C.FindFirstFile(lpFileName &u8, lpFindFileData voidptr) voidptr
|
||||
|
||||
fn C.FindNextFile(hFindFile voidptr, lpFindFileData voidptr) int
|
||||
|
||||
@@ -361,7 +361,7 @@ fn C.closesocket(int) int
|
||||
|
||||
fn C.vschannel_init(&C.TlsContext)
|
||||
|
||||
fn C.request(&C.TlsContext, int, &u16, &byte, &&byte) int
|
||||
fn C.request(&C.TlsContext, int, &u16, &u8, &&u8) int
|
||||
|
||||
fn C.vschannel_cleanup(&C.TlsContext)
|
||||
|
||||
@@ -370,19 +370,19 @@ fn C.URLDownloadToFile(int, &u16, &u16, int, int)
|
||||
[trusted]
|
||||
fn C.GetLastError() u32
|
||||
|
||||
fn C.CreateDirectory(&byte, int) bool
|
||||
fn C.CreateDirectory(&u8, int) bool
|
||||
|
||||
// win crypto
|
||||
fn C.BCryptGenRandom(int, voidptr, int, int) int
|
||||
|
||||
// win synchronization
|
||||
fn C.CreateMutex(int, bool, &byte) voidptr
|
||||
fn C.CreateMutex(int, bool, &u8) voidptr
|
||||
|
||||
fn C.WaitForSingleObject(voidptr, int) int
|
||||
|
||||
fn C.ReleaseMutex(voidptr) bool
|
||||
|
||||
fn C.CreateEvent(int, bool, bool, &byte) voidptr
|
||||
fn C.CreateEvent(int, bool, bool, &u8) voidptr
|
||||
|
||||
fn C.SetEvent(voidptr) int
|
||||
|
||||
@@ -480,4 +480,4 @@ fn C.dup2(oldfd int, newfd int) int
|
||||
fn C.glTexImage2D()
|
||||
|
||||
// used by ios for println
|
||||
fn C.WrappedNSLog(str &byte)
|
||||
fn C.WrappedNSLog(str &u8)
|
||||
|
||||
@@ -77,7 +77,7 @@ fn (nn int) str_l(max int) string {
|
||||
buf[index] = `-`
|
||||
}
|
||||
diff := max - index
|
||||
vmemmove(buf, buf + index, diff + 1)
|
||||
vmemmove(buf, voidptr(buf + index), diff + 1)
|
||||
/*
|
||||
// === manual memory move for bare metal ===
|
||||
mut c:= 0
|
||||
@@ -148,7 +148,7 @@ pub fn (nn u32) str() string {
|
||||
index++
|
||||
}
|
||||
diff := max - index
|
||||
vmemmove(buf, buf + index, diff + 1)
|
||||
vmemmove(buf, voidptr(buf + index), diff + 1)
|
||||
return tos(buf, diff)
|
||||
|
||||
// return tos(memdup(&buf[0] + index, (max - index)), (max - index))
|
||||
@@ -202,7 +202,7 @@ pub fn (nn i64) str() string {
|
||||
buf[index] = `-`
|
||||
}
|
||||
diff := max - index
|
||||
vmemmove(buf, buf + index, diff + 1)
|
||||
vmemmove(buf, voidptr(buf + index), diff + 1)
|
||||
return tos(buf, diff)
|
||||
// return tos(memdup(&buf[0] + index, (max - index)), (max - index))
|
||||
}
|
||||
@@ -239,7 +239,7 @@ pub fn (nn u64) str() string {
|
||||
index++
|
||||
}
|
||||
diff := max - index
|
||||
vmemmove(buf, buf + index, diff + 1)
|
||||
vmemmove(buf, voidptr(buf + index), diff + 1)
|
||||
return tos(buf, diff)
|
||||
// return tos(memdup(&buf[0] + index, (max - index)), (max - index))
|
||||
}
|
||||
@@ -260,13 +260,13 @@ pub fn (b bool) str() string {
|
||||
|
||||
// u64_to_hex converts the number `nn` to a (zero padded if necessary) hexadecimal `string`.
|
||||
[direct_array_access; inline]
|
||||
fn u64_to_hex(nn u64, len byte) string {
|
||||
fn u64_to_hex(nn u64, len u8) string {
|
||||
mut n := nn
|
||||
mut buf := [17]byte{}
|
||||
mut buf := [17]u8{}
|
||||
buf[len] = 0
|
||||
mut i := 0
|
||||
for i = len - 1; i >= 0; i-- {
|
||||
d := byte(n & 0xF)
|
||||
d := u8(n & 0xF)
|
||||
buf[i] = if d < 10 { d + `0` } else { d + 87 }
|
||||
n = n >> 4
|
||||
}
|
||||
@@ -275,13 +275,13 @@ fn u64_to_hex(nn u64, len byte) string {
|
||||
|
||||
// u64_to_hex_no_leading_zeros converts the number `nn` to hexadecimal `string`.
|
||||
[direct_array_access; inline]
|
||||
fn u64_to_hex_no_leading_zeros(nn u64, len byte) string {
|
||||
fn u64_to_hex_no_leading_zeros(nn u64, len u8) string {
|
||||
mut n := nn
|
||||
mut buf := [17]byte{}
|
||||
mut buf := [17]u8{}
|
||||
buf[len] = 0
|
||||
mut i := 0
|
||||
for i = len - 1; i >= 0; i-- {
|
||||
d := byte(n & 0xF)
|
||||
d := u8(n & 0xF)
|
||||
buf[i] = if d < 10 { d + `0` } else { d + 87 }
|
||||
n = n >> 4
|
||||
if n == 0 {
|
||||
@@ -297,7 +297,7 @@ fn u64_to_hex_no_leading_zeros(nn u64, len byte) string {
|
||||
// Example: assert byte(2).hex() == '02'
|
||||
// Example: assert byte(15).hex() == '0f'
|
||||
// Example: assert byte(255).hex() == 'ff'
|
||||
pub fn (nn byte) hex() string {
|
||||
pub fn (nn u8) hex() string {
|
||||
if nn == 0 {
|
||||
return '00'
|
||||
}
|
||||
@@ -406,7 +406,7 @@ pub fn (nn charptr) str() string {
|
||||
return '0x' + u64(nn).hex()
|
||||
}
|
||||
|
||||
pub fn (nn byte) hex_full() string {
|
||||
pub fn (nn u8) hex_full() string {
|
||||
return u64_to_hex(u64(nn), 2)
|
||||
}
|
||||
|
||||
@@ -452,13 +452,13 @@ pub fn (nn u64) hex_full() string {
|
||||
// str returns the contents of `byte` as a zero terminated `string`.
|
||||
// See also: [`byte.ascii_str`](#byte.ascii_str)
|
||||
// Example: assert byte(111).str() == '111'
|
||||
pub fn (b byte) str() string {
|
||||
pub fn (b u8) str() string {
|
||||
return int(b).str_l(7)
|
||||
}
|
||||
|
||||
// ascii_str returns the contents of `byte` as a zero terminated ASCII `string` character.
|
||||
// Example: assert byte(97).ascii_str() == 'a'
|
||||
pub fn (b byte) ascii_str() string {
|
||||
pub fn (b u8) ascii_str() string {
|
||||
mut str := string{
|
||||
str: unsafe { malloc_noscan(2) }
|
||||
len: 1
|
||||
@@ -474,7 +474,7 @@ pub fn (b byte) ascii_str() string {
|
||||
// str_escaped returns the contents of `byte` as an escaped `string`.
|
||||
// Example: assert byte(0).str_escaped() == r'`\0`'
|
||||
[manualfree]
|
||||
pub fn (b byte) str_escaped() string {
|
||||
pub fn (b u8) str_escaped() string {
|
||||
str := match b {
|
||||
0 {
|
||||
r'`\0`'
|
||||
@@ -520,12 +520,12 @@ pub fn (b byte) str_escaped() string {
|
||||
// Example: assert `H`.is_capital() == true
|
||||
// Example: assert `h`.is_capital() == false
|
||||
[inline]
|
||||
pub fn (c byte) is_capital() bool {
|
||||
pub fn (c u8) is_capital() bool {
|
||||
return c >= `A` && c <= `Z`
|
||||
}
|
||||
|
||||
// clone clones the byte array, and returns the newly created copy.
|
||||
pub fn (b []byte) clone() []byte {
|
||||
pub fn (b []u8) clone() []byte {
|
||||
mut res := []byte{len: b.len}
|
||||
// mut res := make([]byte, {repeat:b.len})
|
||||
for i in 0 .. b.len {
|
||||
@@ -539,7 +539,7 @@ pub fn (b []byte) clone() []byte {
|
||||
// even when some of the array bytes were `0`.
|
||||
// If you want to get a V string, that contains only the bytes till
|
||||
// the first `0` byte, use `tos_clone(&byte(array.data))` instead.
|
||||
pub fn (b []byte) bytestr() string {
|
||||
pub fn (b []u8) bytestr() string {
|
||||
unsafe {
|
||||
buf := malloc_noscan(b.len + 1)
|
||||
vmemcpy(buf, b.data, b.len)
|
||||
@@ -552,13 +552,13 @@ pub fn (b []byte) bytestr() string {
|
||||
// from utf8 to utf32 and return the result as a rune
|
||||
// it will produce an error if there are more than
|
||||
// four bytes in the array.
|
||||
pub fn (b []byte) byterune() ?rune {
|
||||
pub fn (b []u8) byterune() ?rune {
|
||||
r := b.utf8_to_utf32() ?
|
||||
return rune(r)
|
||||
}
|
||||
|
||||
// repeat returns a new string with `count` number of copies of the byte it was called on.
|
||||
pub fn (b byte) repeat(count int) string {
|
||||
pub fn (b u8) repeat(count int) string {
|
||||
if count < 0 {
|
||||
panic('byte.repeat: count is negative: $count')
|
||||
} else if count == 0 {
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
module builtin
|
||||
|
||||
pub fn (b byte) is_space() bool {
|
||||
pub fn (b u8) is_space() bool {
|
||||
mut result := false
|
||||
#result.val = /^\s*$/.test(String.fromCharCode(b))
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
pub fn (c byte) str() string {
|
||||
pub fn (c u8) str() string {
|
||||
res := ''
|
||||
#res.str = c.val.toString()
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
pub fn (c byte) ascii_str() string {
|
||||
pub fn (c u8) ascii_str() string {
|
||||
res := ''
|
||||
#res.str = String.fromCharCode(c.val)
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
pub fn (c byte) repeat(count int) string {
|
||||
pub fn (c u8) repeat(count int) string {
|
||||
mut res := ''
|
||||
for _ in 0 .. count {
|
||||
res += c.ascii_str()
|
||||
@@ -31,42 +31,42 @@ pub fn (c byte) repeat(count int) string {
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn (c byte) is_digit() bool {
|
||||
pub fn (c u8) is_digit() bool {
|
||||
return c >= `0` && c <= `9`
|
||||
}
|
||||
|
||||
// is_hex_digit returns `true` if the byte is either in range 0-9, a-f or A-F and `false` otherwise.
|
||||
// Example: assert byte(`F`) == true
|
||||
[inline]
|
||||
pub fn (c byte) is_hex_digit() bool {
|
||||
pub fn (c u8) is_hex_digit() bool {
|
||||
return (c >= `0` && c <= `9`) || (c >= `a` && c <= `f`) || (c >= `A` && c <= `F`)
|
||||
}
|
||||
|
||||
// is_oct_digit returns `true` if the byte is in range 0-7 and `false` otherwise.
|
||||
// Example: assert byte(`7`) == true
|
||||
[inline]
|
||||
pub fn (c byte) is_oct_digit() bool {
|
||||
pub fn (c u8) is_oct_digit() bool {
|
||||
return c >= `0` && c <= `7`
|
||||
}
|
||||
|
||||
// is_bin_digit returns `true` if the byte is a binary digit (0 or 1) and `false` otherwise.
|
||||
// Example: assert byte(`0`) == true
|
||||
[inline]
|
||||
pub fn (c byte) is_bin_digit() bool {
|
||||
pub fn (c u8) is_bin_digit() bool {
|
||||
return c == `0` || c == `1`
|
||||
}
|
||||
|
||||
// is_letter returns `true` if the byte is in range a-z or A-Z and `false` otherwise.
|
||||
// Example: assert byte(`V`) == true
|
||||
[inline]
|
||||
pub fn (c byte) is_letter() bool {
|
||||
pub fn (c u8) is_letter() bool {
|
||||
return (c >= `a` && c <= `z`) || (c >= `A` && c <= `Z`)
|
||||
}
|
||||
|
||||
// is_alnum returns `true` if the byte is in range a-z, A-Z, 0-9 and `false` otherwise.
|
||||
// Example: assert byte(`V`) == true
|
||||
[inline]
|
||||
pub fn (c byte) is_alnum() bool {
|
||||
pub fn (c u8) is_alnum() bool {
|
||||
return (c >= `a` && c <= `z`) || (c >= `A` && c <= `Z`) || (c >= `0` && c <= `9`)
|
||||
}
|
||||
|
||||
@@ -74,14 +74,14 @@ pub fn (c byte) is_alnum() bool {
|
||||
// Example: assert `H`.is_capital() == true
|
||||
// Example: assert `h`.is_capital() == false
|
||||
[inline]
|
||||
pub fn (c byte) is_capital() bool {
|
||||
pub fn (c u8) is_capital() bool {
|
||||
return c >= `A` && c <= `Z`
|
||||
}
|
||||
|
||||
// str_escaped returns the contents of `byte` as an escaped `string`.
|
||||
// Example: assert byte(0).str_escaped() == r'`\0`'
|
||||
|
||||
pub fn (b byte) str_escaped() string {
|
||||
pub fn (b u8) str_escaped() string {
|
||||
mut str := ''
|
||||
match b {
|
||||
0 { str = r'`\0`' }
|
||||
|
||||
@@ -85,9 +85,9 @@ mut:
|
||||
deletes u32 // count
|
||||
// array allocated (with `cap` bytes) on first deletion
|
||||
// has non-zero element when key deleted
|
||||
all_deleted &byte
|
||||
values &byte
|
||||
keys &byte
|
||||
all_deleted &u8
|
||||
values &u8
|
||||
keys &u8
|
||||
}
|
||||
|
||||
[inline]
|
||||
@@ -107,13 +107,13 @@ fn new_dense_array(key_bytes int, value_bytes int) DenseArray {
|
||||
|
||||
[inline]
|
||||
fn (d &DenseArray) key(i int) voidptr {
|
||||
return unsafe { d.keys + i * d.key_bytes }
|
||||
return unsafe { voidptr(d.keys + i * d.key_bytes) }
|
||||
}
|
||||
|
||||
// for cgen
|
||||
[inline]
|
||||
fn (d &DenseArray) value(i int) voidptr {
|
||||
return unsafe { d.values + i * d.value_bytes }
|
||||
return unsafe { voidptr(d.values + i * d.value_bytes) }
|
||||
}
|
||||
|
||||
[inline]
|
||||
@@ -135,7 +135,7 @@ fn (mut d DenseArray) expand() int {
|
||||
d.values = realloc_data(d.values, old_value_size, d.value_bytes * d.cap)
|
||||
if d.deletes != 0 {
|
||||
d.all_deleted = realloc_data(d.all_deleted, old_cap, d.cap)
|
||||
vmemset(d.all_deleted + d.len, 0, d.cap - d.len)
|
||||
vmemset(voidptr(d.all_deleted + d.len), 0, d.cap - d.len)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -167,9 +167,9 @@ mut:
|
||||
// Highest even index in the hashtable
|
||||
even_index u32
|
||||
// Number of cached hashbits left for rehashing
|
||||
cached_hashbits byte
|
||||
cached_hashbits u8
|
||||
// Used for right-shifting out used hashbits
|
||||
shift byte
|
||||
shift u8
|
||||
// Array storing key-values (ordered)
|
||||
key_values DenseArray
|
||||
// Pointer to meta-data:
|
||||
@@ -194,7 +194,7 @@ fn map_eq_string(a voidptr, b voidptr) bool {
|
||||
}
|
||||
|
||||
fn map_eq_int_1(a voidptr, b voidptr) bool {
|
||||
return unsafe { *&byte(a) == *&byte(b) }
|
||||
return unsafe { *&u8(a) == *&u8(b) }
|
||||
}
|
||||
|
||||
fn map_eq_int_2(a voidptr, b voidptr) bool {
|
||||
@@ -218,7 +218,7 @@ fn map_clone_string(dest voidptr, pkey voidptr) {
|
||||
|
||||
fn map_clone_int_1(dest voidptr, pkey voidptr) {
|
||||
unsafe {
|
||||
*&byte(dest) = *&byte(pkey)
|
||||
*&u8(dest) = *&u8(pkey)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -274,8 +274,8 @@ fn new_map(key_bytes int, value_bytes int, hash_fn MapHashFn, key_eq_fn MapEqFn,
|
||||
fn new_map_init(hash_fn MapHashFn, key_eq_fn MapEqFn, clone_fn MapCloneFn, free_fn MapFreeFn, n int, key_bytes int, value_bytes int, keys voidptr, values voidptr) map {
|
||||
mut out := new_map(key_bytes, value_bytes, hash_fn, key_eq_fn, clone_fn, free_fn)
|
||||
// TODO pre-allocate n slots
|
||||
mut pkey := &byte(keys)
|
||||
mut pval := &byte(values)
|
||||
mut pkey := &u8(keys)
|
||||
mut pval := &u8(values)
|
||||
for _ in 0 .. n {
|
||||
unsafe {
|
||||
out.set(pkey, pval)
|
||||
@@ -348,7 +348,7 @@ fn (mut m map) ensure_extra_metas(probe_count u32) {
|
||||
m.extra_metas += extra_metas_inc
|
||||
mem_size := (m.even_index + 2 + m.extra_metas)
|
||||
unsafe {
|
||||
x := realloc_data(&byte(m.metas), int(size_of_u32 * old_mem_size), int(size_of_u32 * mem_size))
|
||||
x := realloc_data(&u8(m.metas), int(size_of_u32 * old_mem_size), int(size_of_u32 * mem_size))
|
||||
m.metas = &u32(x)
|
||||
vmemset(m.metas + mem_size - extra_metas_inc, 0, int(sizeof(u32) * extra_metas_inc))
|
||||
}
|
||||
@@ -388,7 +388,7 @@ fn (mut m map) set(key voidptr, value voidptr) {
|
||||
pkey := m.key_values.key(kv_index)
|
||||
pvalue := m.key_values.value(kv_index)
|
||||
m.clone_fn(pkey, key)
|
||||
vmemcpy(&byte(pvalue), value, m.value_bytes)
|
||||
vmemcpy(&u8(pvalue), value, m.value_bytes)
|
||||
}
|
||||
m.meta_greater(index, meta, u32(kv_index))
|
||||
m.len++
|
||||
@@ -418,7 +418,7 @@ fn (mut m map) rehash() {
|
||||
meta_bytes := sizeof(u32) * (m.even_index + 2 + m.extra_metas)
|
||||
unsafe {
|
||||
// TODO: use realloc_data here too
|
||||
x := v_realloc(&byte(m.metas), int(meta_bytes))
|
||||
x := v_realloc(&u8(m.metas), int(meta_bytes))
|
||||
m.metas = &u32(x)
|
||||
vmemset(m.metas, 0, int(meta_bytes))
|
||||
}
|
||||
@@ -468,7 +468,7 @@ fn (mut m map) get_and_set(key voidptr, zero voidptr) voidptr {
|
||||
pkey := unsafe { m.key_values.key(kv_index) }
|
||||
if m.key_eq_fn(key, pkey) {
|
||||
pval := unsafe { m.key_values.value(kv_index) }
|
||||
return unsafe { &byte(pval) }
|
||||
return unsafe { &u8(pval) }
|
||||
}
|
||||
}
|
||||
index += 2
|
||||
@@ -494,7 +494,7 @@ fn (m &map) get(key voidptr, zero voidptr) voidptr {
|
||||
pkey := unsafe { m.key_values.key(kv_index) }
|
||||
if m.key_eq_fn(key, pkey) {
|
||||
pval := unsafe { m.key_values.value(kv_index) }
|
||||
return unsafe { &byte(pval) }
|
||||
return unsafe { &u8(pval) }
|
||||
}
|
||||
}
|
||||
index += 2
|
||||
@@ -518,7 +518,7 @@ fn (m &map) get_check(key voidptr) voidptr {
|
||||
pkey := unsafe { m.key_values.key(kv_index) }
|
||||
if m.key_eq_fn(key, pkey) {
|
||||
pval := unsafe { m.key_values.value(kv_index) }
|
||||
return unsafe { &byte(pval) }
|
||||
return unsafe { &u8(pval) }
|
||||
}
|
||||
}
|
||||
index += 2
|
||||
@@ -604,7 +604,7 @@ pub fn (mut m map) delete(key voidptr) {
|
||||
// Returns all keys in the map.
|
||||
pub fn (m &map) keys() array {
|
||||
mut keys := __new_array(m.len, 0, m.key_bytes)
|
||||
mut item := unsafe { &byte(keys.data) }
|
||||
mut item := unsafe { &u8(keys.data) }
|
||||
if m.key_values.deletes == 0 {
|
||||
for i := 0; i < m.key_values.len; i++ {
|
||||
unsafe {
|
||||
|
||||
@@ -103,7 +103,7 @@ pub fn error_with_code(message string, code int) IError {
|
||||
|
||||
// Option is the base of V's internal optional return system.
|
||||
struct Option {
|
||||
state byte
|
||||
state u8
|
||||
err IError = none__
|
||||
// Data is trailing after err
|
||||
// and is not included in here but in the
|
||||
@@ -114,7 +114,7 @@ fn opt_ok(data voidptr, mut option Option, size int) {
|
||||
unsafe {
|
||||
*option = Option{}
|
||||
// use err to get the end of OptionBase and then memcpy into it
|
||||
vmemcpy(&byte(&option.err) + sizeof(IError), data, size)
|
||||
vmemcpy(&u8(&option.err) + sizeof(IError), data, size)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ mut:
|
||||
start &byte = 0
|
||||
previous &VMemoryBlock = 0
|
||||
remaining int
|
||||
current &byte = 0
|
||||
current &u8 = 0
|
||||
mallocs int
|
||||
}
|
||||
|
||||
|
||||
@@ -14,14 +14,14 @@ pub fn (c rune) str() string {
|
||||
/*
|
||||
unsafe {
|
||||
fst_byte := int(c)>>8 * 3 & 0xff
|
||||
len := utf8_char_len(byte(fst_byte))
|
||||
len := utf8_char_len(u8(fst_byte))
|
||||
println('len=$len')
|
||||
mut str := string{
|
||||
len: len
|
||||
str: malloc_noscan(len + 1)
|
||||
}
|
||||
for i in 0..len {
|
||||
str.str[i] = byte(int(c)>>8 * (3 - i) & 0xff)
|
||||
str.str[i] = u8(int(c)>>8 * (3 - i) & 0xff)
|
||||
}
|
||||
str.str[len] = `\0`
|
||||
println(str)
|
||||
@@ -49,15 +49,15 @@ pub fn (c rune) repeat(count int) string {
|
||||
} else if count == 1 {
|
||||
return c.str()
|
||||
}
|
||||
mut buffer := [5]byte{}
|
||||
mut buffer := [5]u8{}
|
||||
res := unsafe { utf32_to_str_no_malloc(u32(c), &buffer[0]) }
|
||||
return res.repeat(count)
|
||||
}
|
||||
|
||||
[manualfree]
|
||||
pub fn (c rune) bytes() []byte {
|
||||
mut res := []byte{cap: 5}
|
||||
res.len = unsafe { utf32_decode_to_buffer(u32(c), &byte(res.data)) }
|
||||
pub fn (c rune) bytes() []u8 {
|
||||
mut res := []u8{cap: 5}
|
||||
res.len = unsafe { utf32_decode_to_buffer(u32(c), &u8(res.data)) }
|
||||
return res
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ Note: A V string should be/is immutable from the point of view of
|
||||
*/
|
||||
pub struct string {
|
||||
pub:
|
||||
str &byte = 0 // points to a C style 0 terminated string of bytes.
|
||||
str &u8 = 0 // points to a C style 0 terminated string of bytes.
|
||||
len int // the length of the .str field, excluding the ending 0 byte. It is always equal to strlen(.str).
|
||||
// NB string.is_lit is an enumeration of the following:
|
||||
// .is_lit == 0 => a fresh string, should be freed by autofree
|
||||
@@ -83,7 +83,7 @@ pub fn (s string) runes() []rune {
|
||||
// It will panic, if the pointer `s` is 0.
|
||||
[unsafe]
|
||||
pub fn cstring_to_vstring(s &char) string {
|
||||
return unsafe { tos2(&byte(s)) }.clone()
|
||||
return unsafe { tos2(&u8(s)) }.clone()
|
||||
}
|
||||
|
||||
// tos_clone creates a new V string copy of the C style string, pointed by `s`.
|
||||
@@ -91,7 +91,7 @@ pub fn cstring_to_vstring(s &char) string {
|
||||
// that tos_clone expects `&byte`, while cstring_to_vstring expects &char).
|
||||
// It will panic, if the pointer `s` is 0.
|
||||
[unsafe]
|
||||
pub fn tos_clone(s &byte) string {
|
||||
pub fn tos_clone(s &u8) string {
|
||||
return unsafe { tos2(s) }.clone()
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ pub fn tos_clone(s &byte) string {
|
||||
// It will panic, when the pointer `s` is 0.
|
||||
// See also `tos_clone`.
|
||||
[unsafe]
|
||||
pub fn tos(s &byte, len int) string {
|
||||
pub fn tos(s &u8, len int) string {
|
||||
if s == 0 {
|
||||
panic('tos(): nil string')
|
||||
}
|
||||
@@ -117,7 +117,7 @@ pub fn tos(s &byte, len int) string {
|
||||
// It is the same as `tos3`, but for &byte pointers, avoiding callsite casts.
|
||||
// See also `tos_clone`.
|
||||
[unsafe]
|
||||
pub fn tos2(s &byte) string {
|
||||
pub fn tos2(s &u8) string {
|
||||
if s == 0 {
|
||||
panic('tos2: nil string')
|
||||
}
|
||||
@@ -139,7 +139,7 @@ pub fn tos3(s &char) string {
|
||||
panic('tos3: nil string')
|
||||
}
|
||||
return string{
|
||||
str: unsafe { &byte(s) }
|
||||
str: unsafe { &u8(s) }
|
||||
len: unsafe { vstrlen_char(s) }
|
||||
}
|
||||
}
|
||||
@@ -151,7 +151,7 @@ pub fn tos3(s &char) string {
|
||||
// It is the same as `tos5`, but for &byte pointers, avoiding callsite casts.
|
||||
// See also `tos_clone`.
|
||||
[unsafe]
|
||||
pub fn tos4(s &byte) string {
|
||||
pub fn tos4(s &u8) string {
|
||||
if s == 0 {
|
||||
return ''
|
||||
}
|
||||
@@ -173,7 +173,7 @@ pub fn tos5(s &char) string {
|
||||
return ''
|
||||
}
|
||||
return string{
|
||||
str: unsafe { &byte(s) }
|
||||
str: unsafe { &u8(s) }
|
||||
len: unsafe { vstrlen_char(s) }
|
||||
}
|
||||
}
|
||||
@@ -185,7 +185,7 @@ pub fn tos5(s &char) string {
|
||||
// (i.e. they would be freed by V's -autofree mechanism, when they are no longer used).
|
||||
// See also `tos_clone`.
|
||||
[unsafe]
|
||||
pub fn (bp &byte) vstring() string {
|
||||
pub fn (bp &u8) vstring() string {
|
||||
return string{
|
||||
str: unsafe { bp }
|
||||
len: unsafe { vstrlen(bp) }
|
||||
@@ -198,7 +198,7 @@ pub fn (bp &byte) vstring() string {
|
||||
// does not need to calculate the length of the 0 terminated string.
|
||||
// See also `tos_clone`.
|
||||
[unsafe]
|
||||
pub fn (bp &byte) vstring_with_len(len int) string {
|
||||
pub fn (bp &u8) vstring_with_len(len int) string {
|
||||
return string{
|
||||
str: unsafe { bp }
|
||||
len: len
|
||||
@@ -216,7 +216,7 @@ pub fn (bp &byte) vstring_with_len(len int) string {
|
||||
[unsafe]
|
||||
pub fn (cp &char) vstring() string {
|
||||
return string{
|
||||
str: &byte(cp)
|
||||
str: &u8(cp)
|
||||
len: unsafe { vstrlen_char(cp) }
|
||||
is_lit: 0
|
||||
}
|
||||
@@ -230,7 +230,7 @@ pub fn (cp &char) vstring() string {
|
||||
[unsafe]
|
||||
pub fn (cp &char) vstring_with_len(len int) string {
|
||||
return string{
|
||||
str: &byte(cp)
|
||||
str: &u8(cp)
|
||||
len: len
|
||||
is_lit: 0
|
||||
}
|
||||
@@ -245,7 +245,7 @@ pub fn (cp &char) vstring_with_len(len int) string {
|
||||
// managed/freed by it, for example `os.args` is implemented using it.
|
||||
// See also `tos_clone`.
|
||||
[unsafe]
|
||||
pub fn (bp &byte) vstring_literal() string {
|
||||
pub fn (bp &u8) vstring_literal() string {
|
||||
return string{
|
||||
str: unsafe { bp }
|
||||
len: unsafe { vstrlen(bp) }
|
||||
@@ -259,7 +259,7 @@ pub fn (bp &byte) vstring_literal() string {
|
||||
// does not need to calculate the length of the 0 terminated string.
|
||||
// See also `tos_clone`.
|
||||
[unsafe]
|
||||
pub fn (bp &byte) vstring_literal_with_len(len int) string {
|
||||
pub fn (bp &u8) vstring_literal_with_len(len int) string {
|
||||
return string{
|
||||
str: unsafe { bp }
|
||||
len: len
|
||||
@@ -274,7 +274,7 @@ pub fn (bp &byte) vstring_literal_with_len(len int) string {
|
||||
[unsafe]
|
||||
pub fn (cp &char) vstring_literal() string {
|
||||
return string{
|
||||
str: &byte(cp)
|
||||
str: &u8(cp)
|
||||
len: unsafe { vstrlen_char(cp) }
|
||||
is_lit: 1
|
||||
}
|
||||
@@ -289,7 +289,7 @@ pub fn (cp &char) vstring_literal() string {
|
||||
[unsafe]
|
||||
pub fn (cp &char) vstring_literal_with_len(len int) string {
|
||||
return string{
|
||||
str: &byte(cp)
|
||||
str: &u8(cp)
|
||||
len: len
|
||||
is_lit: 1
|
||||
}
|
||||
@@ -521,7 +521,7 @@ pub fn (s string) f64() f64 {
|
||||
|
||||
// u8 returns the value of the string as u8 `'1'.u8() == u8(1)`.
|
||||
pub fn (s string) byte() u8 {
|
||||
return byte(strconv.common_parse_uint(s, 0, 8, false, false) or { 0 })
|
||||
return u8(strconv.common_parse_uint(s, 0, 8, false, false) or { 0 })
|
||||
}
|
||||
|
||||
// u16 returns the value of the string as u16 `'1'.u16() == u16(1)`.
|
||||
@@ -1039,7 +1039,7 @@ pub fn (s string) index_after(p string, start int) int {
|
||||
// index_byte returns the index of byte `c` if found in the string.
|
||||
// index_byte returns -1 if the byte can not be found.
|
||||
[direct_array_access]
|
||||
pub fn (s string) index_byte(c byte) int {
|
||||
pub fn (s string) index_byte(c u8) int {
|
||||
for i in 0 .. s.len {
|
||||
if unsafe { s.str[i] } == c {
|
||||
return i
|
||||
@@ -1051,7 +1051,7 @@ pub fn (s string) index_byte(c byte) int {
|
||||
// last_index_byte returns the index of the last occurence of byte `c` if found in the string.
|
||||
// last_index_byte returns -1 if the byte is not found.
|
||||
[direct_array_access]
|
||||
pub fn (s string) last_index_byte(c byte) int {
|
||||
pub fn (s string) last_index_byte(c u8) int {
|
||||
for i := s.len - 1; i >= 0; i-- {
|
||||
if unsafe { s.str[i] == c } {
|
||||
return i
|
||||
@@ -1215,7 +1215,7 @@ pub fn (s string) to_upper() string {
|
||||
pub fn (s string) is_upper() bool {
|
||||
for i in 0 .. s.len {
|
||||
if s[i] >= `a` && s[i] <= `z` {
|
||||
return false
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
@@ -1490,7 +1490,7 @@ fn (s string) at(idx int) byte {
|
||||
|
||||
// version of `at()` that is used in `a[i] or {`
|
||||
// return an error when the index is out of range
|
||||
fn (s string) at_with_check(idx int) ?byte {
|
||||
fn (s string) at_with_check(idx int) ?u8 {
|
||||
if idx < 0 || idx >= s.len {
|
||||
return error('string index out of range')
|
||||
}
|
||||
@@ -1503,7 +1503,7 @@ fn (s string) at_with_check(idx int) ?byte {
|
||||
// The following list is considered white space characters: ` `, `\t`, `\n`, `\v`, `\f`, `\r`, 0x85, 0xa0
|
||||
// Example: assert byte(` `).is_space() == true
|
||||
[inline]
|
||||
pub fn (c byte) is_space() bool {
|
||||
pub fn (c u8) is_space() bool {
|
||||
// 0x85 is NEXT LINE (NEL)
|
||||
// 0xa0 is NO-BREAK SPACE
|
||||
return c == 32 || (c > 8 && c < 14) || (c == 0x85) || (c == 0xa0)
|
||||
@@ -1512,42 +1512,42 @@ pub fn (c byte) is_space() bool {
|
||||
// is_digit returns `true` if the byte is in range 0-9 and `false` otherwise.
|
||||
// Example: assert byte(`9`) == true
|
||||
[inline]
|
||||
pub fn (c byte) is_digit() bool {
|
||||
pub fn (c u8) is_digit() bool {
|
||||
return c >= `0` && c <= `9`
|
||||
}
|
||||
|
||||
// is_hex_digit returns `true` if the byte is either in range 0-9, a-f or A-F and `false` otherwise.
|
||||
// Example: assert byte(`F`) == true
|
||||
[inline]
|
||||
pub fn (c byte) is_hex_digit() bool {
|
||||
pub fn (c u8) is_hex_digit() bool {
|
||||
return (c >= `0` && c <= `9`) || (c >= `a` && c <= `f`) || (c >= `A` && c <= `F`)
|
||||
}
|
||||
|
||||
// is_oct_digit returns `true` if the byte is in range 0-7 and `false` otherwise.
|
||||
// Example: assert byte(`7`) == true
|
||||
[inline]
|
||||
pub fn (c byte) is_oct_digit() bool {
|
||||
pub fn (c u8) is_oct_digit() bool {
|
||||
return c >= `0` && c <= `7`
|
||||
}
|
||||
|
||||
// is_bin_digit returns `true` if the byte is a binary digit (0 or 1) and `false` otherwise.
|
||||
// Example: assert byte(`0`) == true
|
||||
[inline]
|
||||
pub fn (c byte) is_bin_digit() bool {
|
||||
pub fn (c u8) is_bin_digit() bool {
|
||||
return c == `0` || c == `1`
|
||||
}
|
||||
|
||||
// is_letter returns `true` if the byte is in range a-z or A-Z and `false` otherwise.
|
||||
// Example: assert byte(`V`) == true
|
||||
[inline]
|
||||
pub fn (c byte) is_letter() bool {
|
||||
pub fn (c u8) is_letter() bool {
|
||||
return (c >= `a` && c <= `z`) || (c >= `A` && c <= `Z`)
|
||||
}
|
||||
|
||||
// is_alnum returns `true` if the byte is in range a-z, A-Z, 0-9 and `false` otherwise.
|
||||
// Example: assert byte(`V`) == true
|
||||
[inline]
|
||||
pub fn (c byte) is_alnum() bool {
|
||||
pub fn (c u8) is_alnum() bool {
|
||||
return (c >= `a` && c <= `z`) || (c >= `A` && c <= `Z`) || (c >= `0` && c <= `9`)
|
||||
}
|
||||
|
||||
@@ -1652,7 +1652,7 @@ pub fn (s string) after(sub string) string {
|
||||
// If the substring is not found, it returns the full input string.
|
||||
// Example: assert '23:34:45.234'.after_char(`:`) == '34:45.234'
|
||||
// Example: assert 'abcd'.after_char(`:`) == 'abcd'
|
||||
pub fn (s string) after_char(sub byte) string {
|
||||
pub fn (s string) after_char(sub u8) string {
|
||||
mut pos := -1
|
||||
for i, c in s {
|
||||
if c == sub {
|
||||
@@ -1685,13 +1685,13 @@ pub fn (a []string) join(sep string) string {
|
||||
mut idx := 0
|
||||
for i, val in a {
|
||||
unsafe {
|
||||
vmemcpy(res.str + idx, val.str, val.len)
|
||||
vmemcpy(voidptr(res.str + idx), val.str, val.len)
|
||||
idx += val.len
|
||||
}
|
||||
// Add sep if it's not last
|
||||
if i != a.len - 1 {
|
||||
unsafe {
|
||||
vmemcpy(res.str + idx, sep.str, sep.len)
|
||||
vmemcpy(voidptr(res.str + idx), sep.str, sep.len)
|
||||
idx += sep.len
|
||||
}
|
||||
}
|
||||
@@ -1751,11 +1751,11 @@ pub fn (s string) hash() int {
|
||||
}
|
||||
|
||||
// bytes returns the string converted to a byte array.
|
||||
pub fn (s string) bytes() []byte {
|
||||
pub fn (s string) bytes() []u8 {
|
||||
if s.len == 0 {
|
||||
return []
|
||||
}
|
||||
mut buf := []byte{len: s.len}
|
||||
mut buf := []u8{len: s.len}
|
||||
unsafe { vmemcpy(buf.data, s.str, s.len) }
|
||||
return buf
|
||||
}
|
||||
@@ -1839,7 +1839,7 @@ pub fn (s string) strip_margin() string {
|
||||
|
||||
// strip_margin_custom does the same as `strip_margin` but will use `del` as delimiter instead of `|`
|
||||
[direct_array_access]
|
||||
pub fn (s string) strip_margin_custom(del byte) string {
|
||||
pub fn (s string) strip_margin_custom(del u8) string {
|
||||
mut sep := del
|
||||
if sep.is_space() {
|
||||
println('Warning: `strip_margin` cannot use white-space as a delimiter')
|
||||
|
||||
@@ -159,7 +159,7 @@ fn (data &StrIntpData) process_str_intp_data(mut sb strings.Builder) {
|
||||
tail_zeros := ((x >> 16) & 0x01) > 0
|
||||
width := int(i16((x >> 17) & 0x3FF))
|
||||
mut base := int(x >> 27) & 0xF
|
||||
fmt_pad_ch := byte((x >> 31) & 0xFF)
|
||||
fmt_pad_ch := u8((x >> 31) & 0xFF)
|
||||
|
||||
// no string interpolation is needed, return empty string
|
||||
if typ == .si_no_str {
|
||||
|
||||
@@ -61,7 +61,7 @@ pub fn string_from_wide2(_wstr &u16, len int) string {
|
||||
// Reads an utf8 character from standard input
|
||||
pub fn utf8_getchar() int {
|
||||
c := C.getchar()
|
||||
len := utf8_len(byte(~c))
|
||||
len := utf8_len(u8(~c))
|
||||
if c < 0 {
|
||||
return 0
|
||||
} else if len == 0 {
|
||||
|
||||
@@ -37,29 +37,29 @@ pub fn utf32_to_str_no_malloc(code u32, buf &byte) string {
|
||||
pub fn utf32_decode_to_buffer(code u32, buf &byte) int {
|
||||
unsafe {
|
||||
icode := int(code) // Prevents doing casts everywhere
|
||||
mut buffer := &byte(buf)
|
||||
mut buffer := &u8(buf)
|
||||
if icode <= 127 {
|
||||
// 0x7F
|
||||
buffer[0] = byte(icode)
|
||||
buffer[0] = u8(icode)
|
||||
return 1
|
||||
} else if icode <= 2047 {
|
||||
// 0x7FF
|
||||
buffer[0] = 192 | byte(icode >> 6) // 0xC0 - 110xxxxx
|
||||
buffer[1] = 128 | byte(icode & 63) // 0x80 - 0x3F - 10xxxxxx
|
||||
buffer[0] = 192 | u8(icode >> 6) // 0xC0 - 110xxxxx
|
||||
buffer[1] = 128 | u8(icode & 63) // 0x80 - 0x3F - 10xxxxxx
|
||||
return 2
|
||||
} else if icode <= 65535 {
|
||||
// 0xFFFF
|
||||
buffer[0] = 224 | byte(icode >> 12) // 0xE0 - 1110xxxx
|
||||
buffer[1] = 128 | (byte(icode >> 6) & 63) // 0x80 - 0x3F - 10xxxxxx
|
||||
buffer[2] = 128 | byte(icode & 63) // 0x80 - 0x3F - 10xxxxxx
|
||||
buffer[0] = 224 | u8(icode >> 12) // 0xE0 - 1110xxxx
|
||||
buffer[1] = 128 | (u8(icode >> 6) & 63) // 0x80 - 0x3F - 10xxxxxx
|
||||
buffer[2] = 128 | u8(icode & 63) // 0x80 - 0x3F - 10xxxxxx
|
||||
return 3
|
||||
}
|
||||
// 0x10FFFF
|
||||
else if icode <= 1114111 {
|
||||
buffer[0] = 240 | byte(icode >> 18) // 0xF0 - 11110xxx
|
||||
buffer[1] = 128 | (byte(icode >> 12) & 63) // 0x80 - 0x3F - 10xxxxxx
|
||||
buffer[2] = 128 | (byte(icode >> 6) & 63) // 0x80 - 0x3F - 10xxxxxx
|
||||
buffer[3] = 128 | byte(icode & 63) // 0x80 - 0x3F - 10xxxxxx
|
||||
buffer[0] = 240 | u8(icode >> 18) // 0xF0 - 11110xxx
|
||||
buffer[1] = 128 | (u8(icode >> 12) & 63) // 0x80 - 0x3F - 10xxxxxx
|
||||
buffer[2] = 128 | (u8(icode >> 6) & 63) // 0x80 - 0x3F - 10xxxxxx
|
||||
buffer[3] = 128 | u8(icode & 63) // 0x80 - 0x3F - 10xxxxxx
|
||||
return 4
|
||||
}
|
||||
}
|
||||
@@ -85,7 +85,7 @@ pub fn (_rune string) utf32_code() int {
|
||||
|
||||
// convert array of utf8 bytes to single utf32 value
|
||||
// will error if more than 4 bytes are submitted
|
||||
pub fn (_bytes []byte) utf8_to_utf32() ?rune {
|
||||
pub fn (_bytes []u8) utf8_to_utf32() ?rune {
|
||||
if _bytes.len == 0 {
|
||||
return 0
|
||||
}
|
||||
@@ -97,7 +97,7 @@ pub fn (_bytes []byte) utf8_to_utf32() ?rune {
|
||||
return error('attempted to decode too many bytes, utf-8 is limited to four bytes maximum')
|
||||
}
|
||||
|
||||
mut b := byte(int(_bytes[0]))
|
||||
mut b := u8(int(_bytes[0]))
|
||||
|
||||
b = b << _bytes.len
|
||||
mut res := rune(b)
|
||||
|
||||
Reference in New Issue
Block a user