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

@ -87,7 +87,7 @@ pub fn common_parse_uint2(s string, _base int, _bit_size int) (u64, int) {
c := s[i]
cl := byte_to_lower(c)
mut d := byte(0)
mut d := u8(0)
if c == `_` && base0 {
// underscore_ok already called
continue

View File

@ -228,7 +228,7 @@ fn f64_to_decimal(mant u64, exp u64) Dec64 {
// Step 4: Find the shortest decimal representation
// in the interval of valid representations.
mut removed := 0
mut last_removed_digit := byte(0)
mut last_removed_digit := u8(0)
mut out := u64(0)
// On average, we remove ~2 digits.
if vm_is_trailing_zeros || vr_is_trailing_zeros {
@ -244,7 +244,7 @@ fn f64_to_decimal(mant u64, exp u64) Dec64 {
vr_mod_10 := vr % 10
vm_is_trailing_zeros = vm_is_trailing_zeros && vm_mod_10 == 0
vr_is_trailing_zeros = vr_is_trailing_zeros && (last_removed_digit == 0)
last_removed_digit = byte(vr_mod_10)
last_removed_digit = u8(vr_mod_10)
vr = vr_div_10
vp = vp_div_10
vm = vm_div_10
@ -261,7 +261,7 @@ fn f64_to_decimal(mant u64, exp u64) Dec64 {
vr_div_10 := vr / 10
vr_mod_10 := vr % 10
vr_is_trailing_zeros = vr_is_trailing_zeros && (last_removed_digit == 0)
last_removed_digit = byte(vr_mod_10)
last_removed_digit = u8(vr_mod_10)
vr = vr_div_10
vp = vp_div_10
vm = vm_div_10

View File

@ -80,7 +80,7 @@ Single format functions
*/
pub struct BF_param {
pub mut:
pad_ch byte = byte(` `) // padding char
pad_ch byte = u8(` `) // padding char
len0 int = -1 // default len for whole the number or string
len1 int = 6 // number of decimal digits, if needed
positive bool = true // mandatory: the sign of the number passed
@ -104,13 +104,13 @@ pub fn format_str(s string, p BF_param) string {
}
if p.allign == .right {
for i1 := 0; i1 < dif; i1++ {
res.write_byte(p.pad_ch)
res.write_u8(p.pad_ch)
}
}
res.write_string(s)
if p.allign == .left {
for i1 := 0; i1 < dif; i1++ {
res.write_byte(p.pad_ch)
res.write_u8(p.pad_ch)
}
}
return res.str()

View File

@ -23,13 +23,13 @@ pub fn format_str_sb(s string, p BF_param, mut sb strings.Builder) {
if p.allign == .right {
for i1 := 0; i1 < dif; i1++ {
sb.write_byte(p.pad_ch)
sb.write_u8(p.pad_ch)
}
}
sb.write_string(s)
if p.allign == .left {
for i1 := 0; i1 < dif; i1++ {
sb.write_byte(p.pad_ch)
sb.write_u8(p.pad_ch)
}
}
}
@ -53,17 +53,17 @@ pub fn format_dec_sb(d u64, p BF_param, mut res strings.Builder) {
if p.pad_ch == `0` {
if p.positive {
if p.sign_flag {
res.write_byte(`+`)
res.write_u8(`+`)
sign_written = true
}
} else {
res.write_byte(`-`)
res.write_u8(`-`)
sign_written = true
}
}
// write the pad chars
for i1 := 0; i1 < dif; i1++ {
res.write_byte(p.pad_ch)
res.write_u8(p.pad_ch)
}
}
@ -71,10 +71,10 @@ pub fn format_dec_sb(d u64, p BF_param, mut res strings.Builder) {
// no pad char, write the sign before the number
if p.positive {
if p.sign_flag {
res.write_byte(`+`)
res.write_u8(`+`)
}
} else {
res.write_byte(`-`)
res.write_u8(`-`)
}
}
@ -85,7 +85,7 @@ pub fn format_dec_sb(d u64, p BF_param, mut res strings.Builder) {
mut i := 20
mut d1 := d
for i >= (21 - n_char) {
buf[i] = byte(d1 % 10) + `0`
buf[i] = u8(d1 % 10) + `0`
d1 = d1 / 10
i--
}
@ -123,13 +123,13 @@ pub fn format_dec_sb(d u64, p BF_param, mut res strings.Builder) {
unsafe { res.write_ptr(&buf[i], n_char) }
} else {
// we have a zero no need of more code!
res.write_byte(`0`)
res.write_u8(`0`)
}
//===========================================
if p.allign == .left {
for i1 := 0; i1 < dif; i1++ {
res.write_byte(p.pad_ch)
res.write_u8(p.pad_ch)
}
}
return

View File

@ -17,7 +17,7 @@ pub fn format_str_sb(s string, p BF_param, mut sb strings.Builder) {
if p.allign == .right {
for i1 := 0; i1 < dif; i1++ {
sb.write_byte(p.pad_ch)
sb.write_u8(p.pad_ch)
}
}
@ -25,7 +25,7 @@ pub fn format_str_sb(s string, p BF_param, mut sb strings.Builder) {
if p.allign == .left {
for i1 := 0; i1 < dif; i1++ {
sb.write_byte(p.pad_ch)
sb.write_u8(p.pad_ch)
}
}
}
@ -49,17 +49,17 @@ pub fn format_dec_sb(d u64, p BF_param, mut res strings.Builder) {
if p.pad_ch == `0` {
if p.positive {
if p.sign_flag {
res.write_byte(`+`)
res.write_u8(`+`)
sign_written = true
}
} else {
res.write_byte(`-`)
res.write_u8(`-`)
sign_written = true
}
}
// write the pad chars
for i1 := 0; i1 < dif; i1++ {
res.write_byte(p.pad_ch)
res.write_u8(p.pad_ch)
}
}
@ -67,10 +67,10 @@ pub fn format_dec_sb(d u64, p BF_param, mut res strings.Builder) {
// no pad char, write the sign before the number
if p.positive {
if p.sign_flag {
res.write_byte(`+`)
res.write_u8(`+`)
}
} else {
res.write_byte(`-`)
res.write_u8(`-`)
}
}
@ -80,7 +80,7 @@ pub fn format_dec_sb(d u64, p BF_param, mut res strings.Builder) {
mut i := 20
mut d1 := d
for i >= (21 - n_char) {
buf[i] = byte(d1 % 10) + `0`
buf[i] = u8(d1 % 10) + `0`
d1 = d1 / 10
i--
@ -88,7 +88,7 @@ pub fn format_dec_sb(d u64, p BF_param, mut res strings.Builder) {
for _ in 0 .. n_char {
i++
res.write_byte(buf[i])
res.write_u8(buf[i])
}
i++
@ -96,7 +96,7 @@ pub fn format_dec_sb(d u64, p BF_param, mut res strings.Builder) {
if p.allign == .left {
for i1 := 0; i1 < dif; i1++ {
res.write_byte(p.pad_ch)
res.write_u8(p.pad_ch)
}
}
return

View File

@ -5,7 +5,7 @@ fn test_format() {
mut tmp_str := ''
a0 := u32(10)
b0 := 200
c0 := byte(12)
c0 := u8(12)
s0 := 'ciAo'
ch0 := `B`
f0 := 0.312345
@ -20,7 +20,7 @@ fn test_format() {
// println("\n$temp_s")
assert tmp_str == temp_s
a := byte(12)
a := u8(12)
b := i16(13)
c := 14
d := i64(15)
@ -31,7 +31,7 @@ fn test_format() {
// println("\n$temp_s")
assert tmp_str == temp_s
a1 := byte(0xff)
a1 := u8(0xff)
b1 := i16(0xffff)
c1 := u32(0xffff_ffff)
d1 := u64(-1)

View File

@ -40,7 +40,7 @@ pub fn v_sprintf(str string, pt ...voidptr) string {
mut len0 := -1 // forced length, if -1 free length
mut len1 := -1 // decimal part for floats
def_len1 := 6 // default value for len1
mut pad_ch := byte(` `) // pad char
mut pad_ch := u8(` `) // pad char
// prefix chars for Length field
mut ch1 := `0` // +1 char if present else `0`
@ -62,7 +62,7 @@ pub fn v_sprintf(str string, pt ...voidptr) string {
ch := str[i]
if ch != `%` && status == .norm_char {
res.write_byte(ch)
res.write_u8(ch)
i++
continue
}
@ -75,8 +75,8 @@ pub fn v_sprintf(str string, pt ...voidptr) string {
// single char, manage it here
if ch == `c` && status == .field_char {
v_sprintf_panic(p_index, pt.len)
d1 := unsafe { *(&byte(pt[p_index])) }
res.write_byte(d1)
d1 := unsafe { *(&u8(pt[p_index])) }
res.write_u8(d1)
status = .reset_params
p_index++
i++
@ -297,7 +297,7 @@ pub fn v_sprintf(str string, pt ...voidptr) string {
// hh fot 8 bit unsigned int
`h` {
if ch2 == `h` {
d1 = u64(unsafe { *(&byte(pt[p_index])) })
d1 = u64(unsafe { *(&u8(pt[p_index])) })
} else {
d1 = u64(unsafe { *(&u16(pt[p_index])) })
}
@ -579,11 +579,11 @@ pub fn format_fl_old(f f64, p BF_param) string {
if p.pad_ch == `0` {
if p.positive {
if p.sign_flag {
res.write_byte(`+`)
res.write_u8(`+`)
sign_len_diff = -1
}
} else {
res.write_byte(`-`)
res.write_u8(`-`)
sign_len_diff = -1
}
tmp := s
@ -611,13 +611,13 @@ pub fn format_fl_old(f f64, p BF_param) string {
if p.allign == .right {
for i1 := 0; i1 < dif; i1++ {
res.write_byte(p.pad_ch)
res.write_u8(p.pad_ch)
}
}
res.write_string(s)
if p.allign == .left {
for i1 := 0; i1 < dif; i1++ {
res.write_byte(p.pad_ch)
res.write_u8(p.pad_ch)
}
}
@ -648,11 +648,11 @@ pub fn format_es_old(f f64, p BF_param) string {
if p.pad_ch == `0` {
if p.positive {
if p.sign_flag {
res.write_byte(`+`)
res.write_u8(`+`)
sign_len_diff = -1
}
} else {
res.write_byte(`-`)
res.write_u8(`-`)
sign_len_diff = -1
}
tmp := s
@ -679,13 +679,13 @@ pub fn format_es_old(f f64, p BF_param) string {
dif := p.len0 - s.len + sign_len_diff
if p.allign == .right {
for i1 := 0; i1 < dif; i1++ {
res.write_byte(p.pad_ch)
res.write_u8(p.pad_ch)
}
}
res.write_string(s)
if p.allign == .left {
for i1 := 0; i1 < dif; i1++ {
res.write_byte(p.pad_ch)
res.write_u8(p.pad_ch)
}
}
return res.str()
@ -697,7 +697,7 @@ pub fn remove_tail_zeros_old(s string) string {
mut last_zero_start := -1
mut dot_pos := -1
mut in_decimal := false
mut prev_ch := byte(0)
mut prev_ch := u8(0)
for i < s.len {
ch := unsafe { s.str[i] }
if ch == `.` {
@ -745,11 +745,11 @@ pub fn format_dec_old(d u64, p BF_param) string {
if p.pad_ch == `0` {
if p.positive {
if p.sign_flag {
res.write_byte(`+`)
res.write_u8(`+`)
sign_len_diff = -1
}
} else {
res.write_byte(`-`)
res.write_u8(`-`)
sign_len_diff = -1
}
tmp := s
@ -776,13 +776,13 @@ pub fn format_dec_old(d u64, p BF_param) string {
if p.allign == .right {
for i1 := 0; i1 < dif; i1++ {
res.write_byte(p.pad_ch)
res.write_u8(p.pad_ch)
}
}
res.write_string(s)
if p.allign == .left {
for i1 := 0; i1 < dif; i1++ {
res.write_byte(p.pad_ch)
res.write_u8(p.pad_ch)
}
}
return res.str()