mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
all: ~500 more byte=>u8
This commit is contained in:
@ -24,7 +24,7 @@ fn init_alphabets() map[string]Alphabet {
|
||||
// will be encoded to and a decode table.
|
||||
struct Alphabet {
|
||||
mut:
|
||||
decode []i8 = []i8{len: 128, init: -1}
|
||||
decode []i8 = []i8{len: 128, init: -1}
|
||||
encode []u8 = []u8{len: 58}
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ module base64
|
||||
// encode_in_buffer returns the size of the encoded data in the buffer.
|
||||
// Please note: The buffer should be large enough (i.e. 4/3 of the data.len, or larger) to hold the encoded data.
|
||||
// Please note: The function does NOT allocate new memory, and is suitable for handling very large strings.
|
||||
pub fn encode_in_buffer(data []u8, buffer &byte) int {
|
||||
pub fn encode_in_buffer(data []u8, buffer &u8) int {
|
||||
return encode_from_buffer(buffer, data.data, data.len)
|
||||
}
|
||||
|
||||
@ -126,8 +126,8 @@ fn decode_from_buffer(dest &u8, src &u8, src_len int) int {
|
||||
for src_len - si >= 8 {
|
||||
// Converting 8 bytes of input into 6 bytes of output. Storing these in the upper bytes of an u64.
|
||||
datablock_64.data = assemble64(u8(index[d[si + 0]]), u8(index[d[si + 1]]),
|
||||
u8(index[d[si + 2]]), u8(index[d[si + 3]]), u8(index[d[si + 4]]),
|
||||
u8(index[d[si + 5]]), u8(index[d[si + 6]]), u8(index[d[si + 7]]))
|
||||
u8(index[d[si + 2]]), u8(index[d[si + 3]]), u8(index[d[si + 4]]), u8(index[d[si + 5]]),
|
||||
u8(index[d[si + 6]]), u8(index[d[si + 7]]))
|
||||
|
||||
// Reading out the individual bytes from the u64. Watch out with endianess.
|
||||
$if little_endian {
|
||||
|
@ -54,13 +54,13 @@ pub fn url_encode_str(data string) string {
|
||||
// assemble64 assembles 8 base64 digits into 6 bytes.
|
||||
// Each digit comes from the decode map.
|
||||
// Please note: Invalid base64 digits are not expected and not handled.
|
||||
fn assemble64(n1 byte, n2 byte, n3 byte, n4 byte, n5 byte, n6 byte, n7 byte, n8 byte) u64 {
|
||||
fn assemble64(n1 u8, n2 u8, n3 u8, n4 u8, n5 u8, n6 u8, n7 u8, n8 u8) u64 {
|
||||
return u64(n1) << 58 | u64(n2) << 52 | u64(n3) << 46 | u64(n4) << 40 | u64(n5) << 34 | u64(n6) << 28 | u64(n7) << 22 | u64(n8) << 16
|
||||
}
|
||||
|
||||
// assemble32 assembles 4 base64 digits into 3 bytes.
|
||||
// Each digit comes from the decode map.
|
||||
// Please note: Invalid base64 digits are not expected and not handled.
|
||||
fn assemble32(n1 byte, n2 byte, n3 byte, n4 byte) u32 {
|
||||
fn assemble32(n1 u8, n2 u8, n3 u8, n4 u8) u32 {
|
||||
return u32(n1) << 26 | u32(n2) << 20 | u32(n3) << 14 | u32(n4) << 8
|
||||
}
|
||||
|
@ -44,16 +44,16 @@ struct Reader {
|
||||
// headings []string
|
||||
data string
|
||||
pub mut:
|
||||
delimiter byte
|
||||
comment byte
|
||||
delimiter u8
|
||||
comment u8
|
||||
is_mac_pre_osx_le bool
|
||||
row_pos int
|
||||
}
|
||||
|
||||
[params]
|
||||
pub struct ReaderConfig {
|
||||
delimiter byte = `,`
|
||||
comment byte = `#`
|
||||
delimiter u8 = `,`
|
||||
comment u8 = `#`
|
||||
}
|
||||
|
||||
// new_reader initializes a Reader with string data to parse and,
|
||||
@ -210,6 +210,6 @@ fn (mut r Reader) read_record() ?[]string {
|
||||
return fields
|
||||
}
|
||||
|
||||
fn valid_delim(b byte) bool {
|
||||
fn valid_delim(b u8) bool {
|
||||
return b != 0 && b != `"` && b != `\r` && b != `\n`
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ mut:
|
||||
sb strings.Builder
|
||||
pub mut:
|
||||
use_crlf bool
|
||||
delimiter byte
|
||||
delimiter u8
|
||||
}
|
||||
|
||||
pub fn new_writer() &Writer {
|
||||
|
@ -52,7 +52,7 @@ pub fn encode(bytes []u8) string {
|
||||
}
|
||||
|
||||
// char2nibble converts an ASCII hex character to it's hex value
|
||||
fn char2nibble(b byte) ?byte {
|
||||
fn char2nibble(b u8) ?u8 {
|
||||
match b {
|
||||
`0`...`9` { return b - u8(`0`) }
|
||||
`A`...`F` { return b - u8(`A`) + 10 }
|
||||
|
@ -11,7 +11,7 @@ pub fn validate_str(str string) bool {
|
||||
return validate(str.str, str.len)
|
||||
}
|
||||
|
||||
pub fn validate(data &byte, len int) bool {
|
||||
pub fn validate(data &u8, len int) bool {
|
||||
mut state := Utf8State{}
|
||||
for i := 0; i < len; i++ {
|
||||
s := unsafe { data[i] }
|
||||
@ -46,7 +46,7 @@ fn (mut s Utf8State) seq(r0 bool, r1 bool, is_tail bool) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
fn (mut s Utf8State) next_state(c byte) {
|
||||
fn (mut s Utf8State) next_state(c u8) {
|
||||
// sequence 1
|
||||
if s.index == 0 {
|
||||
if (c >= 0x00 + 1 && c <= 0x7F) || c == 0x00 {
|
||||
|
Reference in New Issue
Block a user