From e3dca82f9c3f274c95e70e2c2cbdf478ed6d880a Mon Sep 17 00:00:00 2001 From: yuyi Date: Wed, 23 Mar 2022 02:15:59 +0800 Subject: [PATCH] strconv: minor cleanup in f64_to_str_lnd1() (#13804) --- vlib/strconv/format_mem.c.v | 51 +++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/vlib/strconv/format_mem.c.v b/vlib/strconv/format_mem.c.v index 5a5da0d93e..6ef5762d03 100644 --- a/vlib/strconv/format_mem.c.v +++ b/vlib/strconv/format_mem.c.v @@ -158,29 +158,36 @@ pub fn f64_to_str_lnd1(f f64, dec_digit int) string { // get sign and decimal parts for c in s { - if c == `-` { - sgn = -1 - i++ - } else if c == `+` { - sgn = 1 - i++ - } else if c >= `0` && c <= `9` { - b[i1] = c - i1++ - i++ - } else if c == `.` { - if sgn > 0 { - d_pos = i - } else { - d_pos = i - 1 + match c { + `-` { + sgn = -1 + i++ + } + `+` { + sgn = 1 + i++ + } + `0`...`9` { + b[i1] = c + i1++ + i++ + } + `.` { + if sgn > 0 { + d_pos = i + } else { + d_pos = i - 1 + } + i++ + } + `e` { + i++ + break + } + else { + s.free() + return '[Float conversion error!!]' } - i++ - } else if c == `e` { - i++ - break - } else { - s.free() - return '[Float conversion error!!]' } } b[i1] = 0