31 #ifndef ETL_TO_STRING_HELPER_INCLUDED
32 #define ETL_TO_STRING_HELPER_INCLUDED
38 #include "../platform.h"
39 #include "../absolute.h"
40 #include "../negative.h"
41 #include "../basic_format_spec.h"
42 #include "../type_traits.h"
43 #include "../container.h"
44 #include "../absolute.h"
45 #include "../algorithm.h"
46 #include "../iterator.h"
47 #include "../limits.h"
51 namespace private_to_string
53 #if ETL_NOT_USING_64BIT_TYPES
54 typedef int32_t workspace_t;
56 typedef int64_t workspace_t;
62 template <
typename TIString>
65 uint32_t length =
static_cast<uint32_t
>(etl::distance(position, str.end()));
69 uint32_t fill_length = format.
get_width() - length;
74 str.insert(str.end(), fill_length, format.
get_fill());
79 str.insert(position, fill_length, format.
get_fill());
87 template <
typename TIString>
93 typedef typename TIString::value_type type;
94 typedef typename TIString::iterator
iterator;
96 static const type t[] = {
't',
'r',
'u',
'e' };
97 static const type f[] = {
'f',
'a',
'l',
's',
'e' };
121 str.push_back(type(
'1'));
125 str.push_back(type(
'0'));
135 template <
typename T,
typename TIString>
142 typedef typename TIString::value_type type;
143 typedef typename TIString::iterator
iterator;
155 if ((format.
get_base() == 10U) && negative)
157 str.push_back(type(
'-'));
160 str.push_back(type(
'0'));
167 T remainder = etl::absolute(value % T(format.
get_base()));
168 str.push_back((remainder > 9) ? (format.
is_upper_case() ? type(
'A' + (remainder - 10)) : type(
'a' + (remainder - 10))) : type(
'0' + remainder));
169 value = value / T(format.
get_base());
173 if ((format.
get_base() == 10U) && negative)
175 str.push_back(type(
'-'));
184 str.push_back(format.
is_upper_case() ? type(
'B') : type(
'b'));
185 str.push_back(type(
'0'));
191 str.push_back(type(
'0'));
197 str.push_back(format.
is_upper_case() ? type(
'X') : type(
'x'));
198 str.push_back(type(
'0'));
210 etl::reverse(start, str.end());
219 template <
typename TIString>
224 typedef typename TIString::value_type type;
226 static const type n[] = {
'n',
'a',
'n' };
227 static const type i[] = {
'i',
'n',
'f' };
242 template <
typename TIString>
244 const workspace_t fractional,
250 typedef typename TIString::value_type type;
256 str.push_back(type(
'.'));
264 template <
typename T,
typename TIString>
270 typedef typename TIString::iterator
iterator;
271 typedef typename TIString::value_type type;
280 if (isnan(value) || isinf(value))
295 workspace_t multiplier = 1;
297 for (uint32_t i = 0; i < fractional_format.
get_precision(); ++i)
303 T f_integral = (value < T(0.0) ? ceil(value) : floor(value));
304 workspace_t integral =
static_cast<workspace_t
>(f_integral);
307 workspace_t fractional = etl::absolute(
static_cast<workspace_t
>(round((value - f_integral) * multiplier)));
310 if (fractional == multiplier)
325 template <
typename TIString>
331 uintptr_t p =
reinterpret_cast<uintptr_t
>(value);
339 template <
typename TIString>
350 typename TIString::iterator start = str.end();
352 str.insert(str.end(), value.begin(), value.end());
360 template <
typename TSringView,
typename TIString>
371 typename TIString::iterator start = str.end();
373 str.insert(str.end(), value.begin(), value.end());
383 template <
typename TIString>
398 template <
typename TIString>
412 template <
typename TIString>
427 template <
typename TIString>
438 #if ETL_NOT_USING_64BIT_TYPES
442 template <
typename T,
typename TIString>
446 to_string(
const T value, TIString& str,
bool append =
false)
450 etl::private_to_string::add_integral(int32_t(value), str, format, append, etl::is_negative(value));
458 template <
typename T,
typename TIString>
464 etl::private_to_string::add_integral(int32_t(value), str, format, append, etl::is_negative(value));
472 template <
typename T,
typename TIString>
476 to_string(
const T value, TIString& str,
bool append =
false)
488 template <
typename T,
typename TIString>
502 template <
typename T,
typename TIString>
507 to_string(
const T value, TIString& str,
bool append =
false)
519 template <
typename T,
typename TIString>
534 template <
typename T,
typename TIString>
539 to_string(
const T value, TIString& str,
bool append =
false)
551 template <
typename T,
typename TIString>
566 template <
typename T,
typename TIString>
571 to_string(
const T value, TIString& str,
bool append =
false)
583 template <
typename T,
typename TIString>
598 template <
typename T,
typename TIString>
603 to_string(
const T value, TIString& str,
bool append =
false)
615 template <
typename T,
typename TIString>
631 template <
typename T,
typename TIString>
633 to_string(
const T value, TIString& str,
bool append =
false)
645 template <
typename T,
typename TIString>
ETL_CONSTEXPR TContainer::iterator begin(TContainer &container)
Definition: container.h:49
ETL_CONSTEXPR TContainer::iterator end(TContainer &container)
Definition: container.h:99
add_pointer
Definition: type_traits_generator.h:851
enable_if
Definition: type_traits_generator.h:1228
is_same
Definition: type_traits_generator.h:981
is_signed
Definition: type_traits_generator.h:951
is_unsigned
Definition: type_traits_generator.h:961
Definition: absolute.h:37
etl::enable_if<!etl::is_same< T, etl::istring >::value &&!etl::is_same< T, etl::string_view >::value, const etl::istring & >::type to_string(const T value, etl::istring &str, bool append=false)
Definition: to_string.h:50
iterator
Definition: iterator.h:422
void add_floating_point(T value, TIString &str, const etl::basic_format_spec< TIString > &format, bool append)
Helper function for floating point.
Definition: to_string_helper.h:265
void add_alignment(TIString &str, typename TIString::iterator position, const etl::basic_format_spec< TIString > &format)
Helper function for left/right alignment.
Definition: to_string_helper.h:63
void add_nan_inf(const bool not_a_number, const bool infinity, TIString &str)
Helper function for floating point nan and inf.
Definition: to_string_helper.h:220
void add_integral_fractional(const workspace_t integral, const workspace_t fractional, TIString &str, const etl::basic_format_spec< TIString > &integral_format, const etl::basic_format_spec< TIString > &fractional_format, const bool negative)
Helper function for floating point integral and fractional.
Definition: to_string_helper.h:243
void add_string(const TIString &value, TIString &str, const etl::basic_format_spec< TIString > &format, bool append)
Helper function for strings.
Definition: to_string_helper.h:340
void add_string_view(const TSringView &value, TIString &str, const etl::basic_format_spec< TIString > &format, bool append)
Helper function for string views.
Definition: to_string_helper.h:361
void add_boolean(const bool value, TIString &str, const etl::basic_format_spec< TIString > &format, bool append)
Helper function for booleans.
Definition: to_string_helper.h:88
void add_integral(T value, TIString &str, const etl::basic_format_spec< TIString > &format, bool append, const bool negative)
Helper function for integrals.
Definition: to_string_helper.h:136
void add_pointer(const volatile void *value, TIString &str, const etl::basic_format_spec< TIString > &format, bool append)
Helper function for pointers.
Definition: to_string_helper.h:326