summaryrefslogtreecommitdiff
path: root/asl/strings/parse_number_float.cpp
diff options
context:
space:
mode:
authorSteven Le Rouzic <steven.lerouzic@gmail.com>2025-07-03 18:37:18 +0200
committerSteven Le Rouzic <steven.lerouzic@gmail.com>2025-07-04 20:44:04 +0200
commitbcdad5b8762060c82a0b7840cb905e69ddb9a65e (patch)
tree468694d1662c61c12f813689520f43c8e1767538 /asl/strings/parse_number_float.cpp
parentcca2e267241a90f238e424e47501b1e8613a5955 (diff)
Add numbers parsingHEADmain
Diffstat (limited to 'asl/strings/parse_number_float.cpp')
-rw-r--r--asl/strings/parse_number_float.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/asl/strings/parse_number_float.cpp b/asl/strings/parse_number_float.cpp
new file mode 100644
index 0000000..4568278
--- /dev/null
+++ b/asl/strings/parse_number_float.cpp
@@ -0,0 +1,30 @@
+// Copyright 2025 Steven Le Rouzic
+//
+// SPDX-License-Identifier: BSD-3-Clause
+
+#include <fast_float.h>
+
+// We need to isolate fast_float.h completely from asl
+// because it conflicts with our redefinitions of things
+// from the STL. In this case it's operator new, but there
+// might be other conflicts.
+
+namespace asl
+{
+
+extern bool parse_float_impl(const char** begin, const char* end, float* value)
+{
+ auto res = fast_float::from_chars(*begin, end, *value);
+ *begin = res.ptr;
+ return res.ec == std::errc{};
+}
+
+extern bool parse_double_impl(const char** begin, const char* end, double* value)
+{
+ auto res = fast_float::from_chars(*begin, end, *value);
+ *begin = res.ptr;
+ return res.ec == std::errc{};
+}
+
+} // namespace asl
+