4#ifndef TETL_STRINGS_TO_FLOATING_POINT_HPP
5#define TETL_STRINGS_TO_FLOATING_POINT_HPP
7#include <etl/_cctype/isdigit.hpp>
8#include <etl/_cctype/isspace.hpp>
9#include <etl/_string_view/basic_string_view.hpp>
10#include <etl/_type_traits/is_signed.hpp>
20template <
typename Float>
22 char const*
end{
nullptr};
27template <
typename Float>
32 auto afterDecimalPoint =
false;
33 auto leadingSpaces =
true;
36 for (; *ptr !=
'\0'; ++ptr) {
40 leadingSpaces =
false;
43 if (!afterDecimalPoint) {
48 res +=
static_cast<Float>(*ptr -
'0') / div;
50 }
else if (*ptr ==
'.') {
51 afterDecimalPoint =
true;
57 return {.end = ptr, .error = {}, .value = res};
constexpr auto isdigit(int ch) noexcept -> int
Checks if the given character is one of the 10 decimal digits: 0123456789.
Definition isdigit.hpp:16
constexpr auto isspace(int ch) noexcept -> int
Checks if the given character is whitespace character as classified by the default C locale.
Definition isspace.hpp:20
constexpr auto to_floating_point(etl::string_view str) noexcept -> to_floating_point_result< Float >
Definition to_floating_point.hpp:28
to_floating_point_error
Definition to_floating_point.hpp:14
Definition adjacent_find.hpp:9
constexpr auto data() const noexcept -> const_pointer
Returns a pointer to the underlying character array. The pointer is such that the range [data(); data...
Definition basic_string_view.hpp:190
Definition to_floating_point.hpp:21
to_floating_point_error error
Definition to_floating_point.hpp:23
char const * end
Definition to_floating_point.hpp:22
Float value
Definition to_floating_point.hpp:24