8 if (input ==
nullptr) {
12 else if (base == 1 || base > 36) {
17 if (length == buffer_size) {
27 if (errno == ERANGE) {
31 else if ((internal_next == original_input) || (internal_next ==
nullptr)) {
32 internal_next =
nullptr;
36 if (external_next !=
nullptr) {
37 *external_next = internal_next;
47 template <
typename T,
typename T
internal, T
internal (*F)(const
char*,
char**,
int)>
49 static_assert(std::numeric_limits<T>::is_integer,
"Type must be integer");
50 static_assert(std::numeric_limits<Tinternal>::is_integer,
"Type must be integer");
51 static_assert(std::numeric_limits<T>::is_signed == std::numeric_limits<Tinternal>::is_signed,
"Signedness must match");
52 static_assert(std::numeric_limits<T>::max() <= std::numeric_limits<Tinternal>::max(),
"Invalid internal type chosen");
55 char* output_next =
nullptr;
58 Tinternal output_api = F(input, &output_next, base);
59 if (output_api > std::numeric_limits<T>::max()) {
61 output_api = std::numeric_limits<T>::max();
67 output =
static_cast<T
>(output_api);
75 return string_to_number_as_template<U64, unsigned long long, strtoull>(input, buffer_size, output, next, base);
79 return string_to_number_as_template<I64, long long, strtoll>(input, buffer_size, output, next, base);
84 return string_to_number_as_template<U32, unsigned long long, strtoull>(input, buffer_size, output, next, base);
89 return string_to_number_as_template<I32, long long, strtoll>(input, buffer_size, output, next, base);
94 return string_to_number_as_template<U16, unsigned long long, strtoull>(input, buffer_size, output, next, base);
97 return string_to_number_as_template<I16, long long, strtoll>(input, buffer_size, output, next, base);
101 return string_to_number_as_template<U8, unsigned long long, strtoull>(input, buffer_size, output, next, base);
104 return string_to_number_as_template<I8, long long, strtoll>(input, buffer_size, output, next, base);
108 char* output_next =
nullptr;
111 output = strtod(input, &output_next);
119 char* output_next =
nullptr;
122 output = strtof(input, &output_next);
int8_t I8
8-bit signed integer
float F32
32-bit floating point
uint8_t U8
8-bit unsigned integer
static U32 min(const U32 a, const U32 b)
PlatformSizeType FwSizeType
Fw::StringUtils::StringToNumberStatus string_to_helper_output_check(Fw::StringUtils::StringToNumberStatus status, const char *original_input, char *&internal_next, char **external_next)
Fw::StringUtils::StringToNumberStatus string_to_helper_input_check(const CHAR *input, FwSizeType buffer_size, U8 base)
Fw::StringUtils::StringToNumberStatus string_to_number_as_template(const CHAR *input, FwSizeType buffer_size, T &output, char **next, U8 base)
FwSizeType string_length(const CHAR *source, FwSizeType buffer_size)
get the length of the source string
@ INVALID_BASE
Base was not supplied as 0, or 2-36.
@ SUCCESSFUL_CONVERSION
Output should be valid.
@ NULL_INPUT
A null string was supplied.
@ INVALID_NUMBER
String did not contain a valid number matching supplied base.
@ INVALID_STRING
No \0 detected within the supplied length.
StringToNumberStatus string_to_number(const CHAR *input, FwSizeType buffer_size, U8 &output, char **next, U8 base=0)
converts a string to a U8