|
28 | 28 | #ifndef SSR_FUDI_PARSER_H |
29 | 29 | #define SSR_FUDI_PARSER_H |
30 | 30 |
|
31 | | -#include <cstdlib> // for std::strtof(), std::strtoul() |
| 31 | +#include <charconv> // for std::from_chars |
32 | 32 | #include <functional> // for std::function |
33 | 33 | #include <variant> |
34 | 34 |
|
@@ -280,9 +280,10 @@ constexpr auto parse_string(std::string& value) |
280 | 280 | constexpr auto id_or_number(std::variant<std::string, unsigned int>& value) |
281 | 281 | { |
282 | 282 | return [&value](std::string_view& input) { |
283 | | - char* str_end; |
284 | | - unsigned int number = std::strtoul(input.data(), &str_end, 10); |
285 | | - if (str_end == input.data()) |
| 283 | + unsigned int number{}; |
| 284 | + auto [str_end, ec] = std::from_chars( |
| 285 | + input.data(), input.data() + input.size(), number); |
| 286 | + if (ec != std::errc()) |
286 | 287 | { |
287 | 288 | std::string temp; |
288 | 289 | auto result = parse_string(temp)(input); |
@@ -333,10 +334,9 @@ constexpr auto parse_float(float& value) |
333 | 334 | { |
334 | 335 | return Match::incomplete; |
335 | 336 | } |
336 | | - char* str_end; |
337 | | - // TODO: use std::from_chars once it is widely available |
338 | | - value = std::strtof(temp.data(), &str_end); |
339 | | - if (str_end == temp.data()) |
| 337 | + auto [str_end, ec] = std::from_chars( |
| 338 | + temp.data(), temp.data() + temp.size(), value); |
| 339 | + if (ec != std::errc()) |
340 | 340 | { |
341 | 341 | return Match::no; |
342 | 342 | } |
|
0 commit comments