1
0
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:
Alexander Medvednikov
2022-04-15 14:58:56 +03:00
parent b49d873217
commit d4a0d6f73c
221 changed files with 1365 additions and 1365 deletions

View File

@@ -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]

View File

@@ -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')

View File

@@ -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