(s string)
| 171 | } |
| 172 | |
| 173 | func parseFloatString(s string) float64 { |
| 174 | var hasDot, hasExp bool |
| 175 | |
| 176 | // <a> |
| 177 | // <a>.<b> |
| 178 | // <a>.<b>e<c> |
| 179 | // <a>e<c> |
| 180 | var a, b, c, rest string |
| 181 | |
| 182 | a, rest, hasDot = strings.Cut(s, ".") |
| 183 | if hasDot { |
| 184 | // <a>.<b> |
| 185 | // <a>.<b>e<c> |
| 186 | b, c, hasExp = cutAny(rest, "eE") |
| 187 | } else { |
| 188 | // <a> |
| 189 | // <a>e<c> |
| 190 | a, c, hasExp = cutAny(s, "eE") |
| 191 | } |
| 192 | |
| 193 | var sb strings.Builder |
| 194 | sb.Grow(len(a) + len(b) + len(c) + 3) |
| 195 | |
| 196 | if a == "" { |
| 197 | if hasDot && b == "" { |
| 198 | return math.NaN() |
| 199 | } |
| 200 | if hasExp && c == "" { |
| 201 | return math.NaN() |
| 202 | } |
| 203 | sb.WriteString("0") |
| 204 | } else { |
| 205 | a = trimLeadingZeros(a) |
| 206 | if !isAllDigits(a) { |
| 207 | return math.NaN() |
| 208 | } |
| 209 | sb.WriteString(a) |
| 210 | } |
| 211 | |
| 212 | if hasDot { |
| 213 | sb.WriteString(".") |
| 214 | if b == "" { |
| 215 | sb.WriteString("0") |
| 216 | } else { |
| 217 | b = trimTrailingZeros(b) |
| 218 | if !isAllDigits(b) { |
| 219 | return math.NaN() |
| 220 | } |
| 221 | sb.WriteString(b) |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | if hasExp { |
| 226 | sb.WriteString("e") |
| 227 | |
| 228 | c, negative := strings.CutPrefix(c, "-") |
| 229 | if negative { |
| 230 | sb.WriteString("-") |
no test coverage detected