1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

parser: remove ++/-- exception for some modules (#9895)

This commit is contained in:
Enzo
2021-04-27 00:41:42 +02:00
committed by GitHub
parent 3877522ee3
commit 4eb8072882
10 changed files with 116 additions and 58 deletions

View File

@@ -205,10 +205,12 @@ fn parser(s string) (int,PrepNumber) {
// skip the inital zeros
fsm_c {
if c == c_zero {
c = s[i++]
c = s[i]
i++
}
else if c == c_dpoint {
c = s[i++]
c = s[i]
i++
state = fsm_d
}
else {
@@ -218,7 +220,8 @@ fn parser(s string) (int,PrepNumber) {
// reading leading zeros in the fractional part of mantissa
fsm_d {
if c == c_zero {
c = s[i++]
c = s[i]
i++
if pn.exponent > -2147483647 {
pn.exponent--
}
@@ -238,10 +241,12 @@ fn parser(s string) (int,PrepNumber) {
else if pn.exponent < 2147483647 {
pn.exponent++
}
c = s[i++]
c = s[i]
i++
}
else if c == c_dpoint {
c = s[i++]
c = s[i]
i++
state = fsm_f
}
else {
@@ -257,10 +262,12 @@ fn parser(s string) (int,PrepNumber) {
pn.exponent--
digx++
}
c = s[i++]
c = s[i]
i++
}
else if is_exp(c) {
c = s[i++]
c = s[i]
i++
state = fsm_g
}
else {
@@ -270,18 +277,21 @@ fn parser(s string) (int,PrepNumber) {
// reading sign of exponent
fsm_g {
if c == c_plus {
c = s[i++]
c = s[i]
i++
}
else if c == c_minus {
expneg = true
c = s[i++]
c = s[i]
i++
}
state = fsm_h
}
// skipping leading zeros of exponent
fsm_h {
if c == c_zero {
c = s[i++]
c = s[i]
i++
}
else {
state = fsm_i
@@ -294,7 +304,8 @@ fn parser(s string) (int,PrepNumber) {
expexp *= 10
expexp += int(c - c_zero)
}
c = s[i++]
c = s[i]
i++
}
else {
state = fsm_stop

View File

@@ -114,7 +114,8 @@ pub fn (d Dec32) get_string_32(neg bool, i_n_digit int, i_pad_digit int) string
}
for fw_zeros > 0 {
buf[i++] = `0`
buf[i] = `0`
i++
fw_zeros--
}

View File

@@ -130,7 +130,8 @@ fn (d Dec64) get_string_64(neg bool, i_n_digit int, i_pad_digit int) string {
}
for fw_zeros > 0 {
buf[i++] = `0`
buf[i] = `0`
i++
fw_zeros--
}

View File

@@ -97,7 +97,8 @@ pub fn f64_to_str_lnd(f f64, dec_digit int) string {
i++
}
else if c >= `0` && c <= `9` {
b[i1++] = c
b[i1] = c
i1++
i++
} else if c == `.` {
if sgn > 0 {
@@ -136,51 +137,59 @@ pub fn f64_to_str_lnd(f f64, dec_digit int) string {
if sgn == 1 {
if m_sgn_flag {
res[r_i++] = `+`
res[r_i] = `+`
r_i++
}
} else {
res[r_i++] = `-`
res[r_i] = `-`
r_i++
}
i = 0
if exp_sgn >= 0 {
for b[i] != 0 {
res[r_i++] = b[i]
res[r_i] = b[i]
r_i++
i++
if i >= d_pos && exp >= 0 {
if exp == 0 {
dot_res_sp = r_i
res[r_i++] = `.`
res[r_i] = `.`
r_i++
}
exp--
}
}
for exp >= 0 {
res[r_i++] = `0`
res[r_i] = `0`
r_i++
exp--
}
//println("exp: $exp $r_i $dot_res_sp")
} else {
mut dot_p := true
for exp > 0 {
res[r_i++] = `0`
res[r_i] = `0`
r_i++
exp--
if dot_p {
dot_res_sp = r_i
res[r_i++] = `.`
res[r_i] = `.`
r_i++
dot_p = false
}
}
for b[i] != 0 {
res[r_i++] = b[i]
res[r_i] = b[i]
r_i++
i++
}
}
// no more digits needed, stop here
if dec_digit <= 0 {
if dec_digit <= 0 {
return unsafe { tos(res.data, dot_res_sp) }
}
}
//println("r_i-d_pos: ${r_i - d_pos}")
if dot_res_sp >= 0 {
@@ -193,9 +202,11 @@ pub fn f64_to_str_lnd(f f64, dec_digit int) string {
} else {
if dec_digit > 0 {
mut c := 0
res[r_i++] = `.`
res[r_i] = `.`
r_i++
for c < dec_digit {
res[r_i++] = `0`
res[r_i] = `0`
r_i++
c++
}
res[r_i] = 0

View File

@@ -260,7 +260,8 @@ pub fn f64_to_str_l(f f64) string {
i++
}
else if c >= `0` && c <= `9` {
b[i1++] = c
b[i1] = c
i1++
i++
} else if c == `.` {
if sgn > 0 {
@@ -298,40 +299,48 @@ pub fn f64_to_str_l(f f64) string {
if sgn == 1 {
if m_sgn_flag {
res[r_i++] = `+`
res[r_i] = `+`
r_i++
}
} else {
res[r_i++] = `-`
res[r_i] = `-`
r_i++
}
i = 0
if exp_sgn >= 0 {
for b[i] != 0 {
res[r_i++] = b[i]
res[r_i] = b[i]
r_i++
i++
if i >= d_pos && exp >= 0 {
if exp == 0 {
res[r_i++] = `.`
res[r_i] = `.`
r_i++
}
exp--
}
}
for exp >= 0 {
res[r_i++] = `0`
res[r_i] = `0`
r_i++
exp--
}
} else {
mut dot_p := true
for exp > 0 {
res[r_i++] = `0`
res[r_i] = `0`
r_i++
exp--
if dot_p {
res[r_i++] = `.`
res[r_i] = `.`
r_i++
dot_p = false
}
}
for b[i] != 0 {
res[r_i++] = b[i]
res[r_i] = b[i]
r_i++
i++
}
}