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:
@@ -22,17 +22,17 @@ const true_in_bytes = 'true'.bytes()
|
||||
|
||||
const false_in_bytes = 'false'.bytes()
|
||||
|
||||
const zero_in_bytes = [byte(`0`)]
|
||||
const zero_in_bytes = [u8(`0`)]
|
||||
|
||||
const comma_bytes = [byte(`,`)]
|
||||
const comma_bytes = [u8(`,`)]
|
||||
|
||||
const colon_bytes = [byte(`:`)]
|
||||
const colon_bytes = [u8(`:`)]
|
||||
|
||||
const space_bytes = [byte(` `)]
|
||||
const space_bytes = [u8(` `)]
|
||||
|
||||
const unicode_escape_chars = [byte(`\\`), `u`]
|
||||
const unicode_escape_chars = [u8(`\\`), `u`]
|
||||
|
||||
const quote_bytes = [byte(`"`)]
|
||||
const quote_bytes = [u8(`"`)]
|
||||
|
||||
const escaped_chars = [(r'\b').bytes(), (r'\f').bytes(), (r'\n').bytes(),
|
||||
(r'\r').bytes(), (r'\t').bytes()]
|
||||
@@ -78,7 +78,7 @@ fn (e &Encoder) encode_value_with_level(f Any, level int, mut wr io.Writer) ? {
|
||||
wr.write(json2.zero_in_bytes) ?
|
||||
}
|
||||
map[string]Any {
|
||||
wr.write([byte(`{`)]) ?
|
||||
wr.write([u8(`{`)]) ?
|
||||
mut i := 0
|
||||
for k, v in f {
|
||||
e.encode_newline(level, mut wr) ?
|
||||
@@ -94,10 +94,10 @@ fn (e &Encoder) encode_value_with_level(f Any, level int, mut wr io.Writer) ? {
|
||||
i++
|
||||
}
|
||||
e.encode_newline(level - 1, mut wr) ?
|
||||
wr.write([byte(`}`)]) ?
|
||||
wr.write([u8(`}`)]) ?
|
||||
}
|
||||
[]Any {
|
||||
wr.write([byte(`[`)]) ?
|
||||
wr.write([u8(`[`)]) ?
|
||||
for i, v in f {
|
||||
e.encode_newline(level, mut wr) ?
|
||||
e.encode_value_with_level(v, level + 1, mut wr) ?
|
||||
@@ -106,7 +106,7 @@ fn (e &Encoder) encode_value_with_level(f Any, level int, mut wr io.Writer) ? {
|
||||
}
|
||||
}
|
||||
e.encode_newline(level - 1, mut wr) ?
|
||||
wr.write([byte(`]`)]) ?
|
||||
wr.write([u8(`]`)]) ?
|
||||
}
|
||||
Null {
|
||||
wr.write(json2.null_in_bytes) ?
|
||||
@@ -180,7 +180,7 @@ fn (mut iter CharLengthIterator) next() ?int {
|
||||
mut len := 1
|
||||
c := iter.text[iter.idx]
|
||||
if (c & (1 << 7)) != 0 {
|
||||
for t := byte(1 << 6); (c & t) != 0; t >>= 1 {
|
||||
for t := u8(1 << 6); (c & t) != 0; t >>= 1 {
|
||||
len++
|
||||
iter.idx++
|
||||
}
|
||||
@@ -207,7 +207,7 @@ fn (e &Encoder) encode_string(s string, mut wr io.Writer) ? {
|
||||
}
|
||||
}
|
||||
} else if chr == `"` || chr == `/` || chr == `\\` {
|
||||
wr.write([byte(`\\`), chr]) ?
|
||||
wr.write([u8(`\\`), chr]) ?
|
||||
} else if int(chr) < 0x20 {
|
||||
hex_code := chr.hex().bytes()
|
||||
wr.write(json2.unicode_escape_chars) ? // \u
|
||||
@@ -215,7 +215,7 @@ fn (e &Encoder) encode_string(s string, mut wr io.Writer) ? {
|
||||
wr.write(json2.zero_in_bytes) ? // \u00
|
||||
wr.write(hex_code) ? // \u00xxxx
|
||||
} else {
|
||||
wr.write([byte(chr)]) ?
|
||||
wr.write([u8(chr)]) ?
|
||||
}
|
||||
} else {
|
||||
slice := s[i..i + char_len]
|
||||
|
||||
@@ -65,7 +65,7 @@ const (
|
||||
34: `"`
|
||||
47: `/`
|
||||
}
|
||||
exp_signs = [byte(`-`), `+`]
|
||||
exp_signs = [u8(`-`), `+`]
|
||||
)
|
||||
|
||||
// move_pos proceeds to the next position.
|
||||
@@ -135,7 +135,7 @@ fn (mut s Scanner) text_scan() Token {
|
||||
} else if (s.pos - 1 >= 0 && s.text[s.pos - 1] != `\\`)
|
||||
&& ch in json2.important_escapable_chars {
|
||||
return s.error('character must be escaped with a backslash')
|
||||
} else if (s.pos == s.text.len - 1 && ch == `\\`) || ch == byte(0) {
|
||||
} else if (s.pos == s.text.len - 1 && ch == `\\`) || ch == u8(0) {
|
||||
return s.error('invalid backslash escape')
|
||||
} else if s.pos + 1 < s.text.len && ch == `\\` {
|
||||
peek := s.text[s.pos + 1]
|
||||
@@ -179,7 +179,7 @@ fn (mut s Scanner) text_scan() Token {
|
||||
}
|
||||
} else if peek == `U` {
|
||||
return s.error('unicode endpoints must be in lowercase `u`')
|
||||
} else if peek == byte(229) {
|
||||
} else if peek == u8(229) {
|
||||
return s.error('unicode endpoint not allowed')
|
||||
} else {
|
||||
return s.error('invalid backslash escape')
|
||||
|
||||
@@ -42,7 +42,7 @@ fn test_str_invalid_escape() {
|
||||
fn test_str_invalid_must_be_escape() {
|
||||
for char in important_escapable_chars {
|
||||
mut sc := Scanner{
|
||||
text: [byte(`"`), `t`, char, `"`]
|
||||
text: [u8(`"`), `t`, char, `"`]
|
||||
}
|
||||
tok := sc.scan()
|
||||
assert tok.kind == .error
|
||||
|
||||
@@ -51,15 +51,15 @@ fn dprintln(txt string) {
|
||||
******************************************************************************/
|
||||
// transform the bitmap from one layer to color layers
|
||||
fn (mut bmp BitMap) format_texture() {
|
||||
r := byte(bmp.color >> 24)
|
||||
g := byte((bmp.color >> 16) & 0xFF)
|
||||
b := byte((bmp.color >> 8) & 0xFF)
|
||||
a := byte(bmp.color & 0xFF)
|
||||
r := u8(bmp.color >> 24)
|
||||
g := u8((bmp.color >> 16) & 0xFF)
|
||||
b := u8((bmp.color >> 8) & 0xFF)
|
||||
a := u8(bmp.color & 0xFF)
|
||||
|
||||
b_r := byte(bmp.bg_color >> 24)
|
||||
b_g := byte((bmp.bg_color >> 16) & 0xFF)
|
||||
b_b := byte((bmp.bg_color >> 8) & 0xFF)
|
||||
b_a := byte(bmp.bg_color & 0xFF)
|
||||
b_r := u8(bmp.bg_color >> 24)
|
||||
b_g := u8((bmp.bg_color >> 16) & 0xFF)
|
||||
b_b := u8((bmp.bg_color >> 8) & 0xFF)
|
||||
b_a := u8(bmp.bg_color & 0xFF)
|
||||
|
||||
// trasform buffer in a texture
|
||||
x := bmp.buf
|
||||
@@ -72,7 +72,7 @@ fn (mut bmp BitMap) format_texture() {
|
||||
x[i + 1] = g
|
||||
x[i + 2] = b
|
||||
// alpha
|
||||
x[i + 3] = byte(u16(a * data) >> 8)
|
||||
x[i + 3] = u8(u16(a * data) >> 8)
|
||||
} else {
|
||||
x[i + 0] = b_r
|
||||
x[i + 1] = b_g
|
||||
|
||||
@@ -195,12 +195,12 @@ pub fn (mut bmp BitMap) plot(x int, y int, c u32) bool {
|
||||
mut index := (x + y * bmp.width) * bmp.bp
|
||||
unsafe {
|
||||
// bmp.buf[index]=0xFF
|
||||
bmp.buf[index] = byte(c & 0xFF) // write only the alpha
|
||||
bmp.buf[index] = u8(c & 0xFF) // write only the alpha
|
||||
}
|
||||
/*
|
||||
for count in 0..(bmp.bp) {
|
||||
unsafe{
|
||||
bmp.buf[index + count] = byte((c >> (bmp.bp - count - 1) * 8) & 0x0000_00FF)
|
||||
bmp.buf[index + count] = u8((c >> (bmp.bp - count - 1) * 8) & 0x0000_00FF)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -493,7 +493,7 @@ fn (mut tf TTF_File) read_compound_glyph(mut in_glyph Glyph) {
|
||||
fn (mut tf TTF_File) get_u8() byte {
|
||||
x := tf.buf[tf.pos]
|
||||
tf.pos++
|
||||
return byte(x)
|
||||
return u8(x)
|
||||
}
|
||||
|
||||
fn (mut tf TTF_File) get_i8() i8 {
|
||||
@@ -540,7 +540,7 @@ fn (mut tf TTF_File) get_fixed() f32 {
|
||||
fn (mut tf TTF_File) get_string(length int) string {
|
||||
tmp_pos := u64(tf.pos)
|
||||
tf.pos += u32(length)
|
||||
return unsafe { tos(&byte(u64(tf.buf.data) + tmp_pos), length) }
|
||||
return unsafe { tos(&u8(u64(tf.buf.data) + tmp_pos), length) }
|
||||
}
|
||||
|
||||
fn (mut tf TTF_File) get_unicode_string(length int) string {
|
||||
@@ -552,12 +552,12 @@ fn (mut tf TTF_File) get_unicode_string(length int) string {
|
||||
c_len := ((0xe5000000 >> ((c >> 3) & 0x1e)) & 3) + 1
|
||||
real_len += c_len
|
||||
if c_len == 1 {
|
||||
tmp_txt.write_byte(byte(c & 0xff))
|
||||
tmp_txt.write_u8(u8(c & 0xff))
|
||||
} else {
|
||||
tmp_txt.write_byte(byte((c >> 8) & 0xff))
|
||||
tmp_txt.write_byte(byte(c & 0xff))
|
||||
tmp_txt.write_u8(u8((c >> 8) & 0xff))
|
||||
tmp_txt.write_u8(u8(c & 0xff))
|
||||
}
|
||||
// dprintln("c: ${c:c}|${ byte(c &0xff) :c} c_len: ${c_len} str_len: ${real_len} in_len: ${length}")
|
||||
// dprintln("c: ${c:c}|${ u8(c &0xff) :c} c_len: ${c_len} str_len: ${real_len} in_len: ${length}")
|
||||
}
|
||||
tf.pos += u32(real_len)
|
||||
res_txt := tmp_txt.str()
|
||||
@@ -1056,7 +1056,7 @@ fn tst() {
|
||||
mut tf := TTF_File{}
|
||||
|
||||
tf.buf = [
|
||||
byte(0xFF), /* 8 bit */
|
||||
u8(0xFF), /* 8 bit */
|
||||
0xF1,
|
||||
0xF2, /* 16 bit */
|
||||
0x81,
|
||||
|
||||
@@ -228,7 +228,7 @@ fn get_raw_data(data string) []byte {
|
||||
}
|
||||
|
||||
if c == 2 {
|
||||
buf << byte(b)
|
||||
buf << u8(b)
|
||||
b = 0
|
||||
c = 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user