31#ifndef ETL_TO_STRING_HELPER_INCLUDED
32#define ETL_TO_STRING_HELPER_INCLUDED
50#if ETL_USING_STL && ETL_USING_CPP11
56 namespace private_to_string
58#if ETL_NOT_USING_64BIT_TYPES
59 typedef int32_t workspace_t;
60 typedef uint32_t uworkspace_t;
62 typedef int64_t workspace_t;
63 typedef uint64_t uworkspace_t;
69 template <
typename TIString>
72 uint32_t length =
static_cast<uint32_t
>(etl::distance(position, str.end()));
76 uint32_t fill_length = format.
get_width() - length;
81 str.insert(str.end(), fill_length, format.
get_fill());
86 str.insert(position, fill_length, format.
get_fill());
94 template <
typename TIString>
100 typedef typename TIString::value_type
type;
101 typedef typename TIString::iterator
iterator;
103 static const type t[] = {
't',
'r',
'u',
'e' };
104 static const type f[] = {
'f',
'a',
'l',
's',
'e' };
117 str.insert(str.end(), ETL_OR_STD11::begin(t), ETL_OR_STD11::end(t));
121 str.insert(str.end(), ETL_OR_STD11::begin(f), ETL_OR_STD11::end(f));
128 str.push_back(
type(
'1'));
132 str.push_back(
type(
'0'));
142 template <
typename T,
typename TIString>
149 typedef typename TIString::value_type
type;
150 typedef typename TIString::iterator
iterator;
162 if ((format.
get_base() == 10U) && negative)
164 str.push_back(
type(
'-'));
167 str.push_back(
type(
'0'));
174 T remainder = etl::absolute(value % T(format.
get_base()));
175 str.push_back((remainder > 9) ? (format.
is_upper_case() ?
type(
'A' + (remainder - 10)) :
type(
'a' + (remainder - 10))) :
type(
'0' + remainder));
176 value = value / T(format.
get_base());
180 if ((format.
get_base() == 10U) && negative)
182 str.push_back(
type(
'-'));
192 str.push_back(
type(
'0'));
198 str.push_back(
type(
'0'));
205 str.push_back(
type(
'0'));
217 etl::reverse(start, str.end());
226 template <
typename TIString>
231 typedef typename TIString::value_type
type;
233 static const type n[] = {
'n',
'a',
'n' };
234 static const type i[] = {
'i',
'n',
'f' };
238 str.insert(str.end(), ETL_OR_STD11::begin(n), ETL_OR_STD11::end(n));
242 str.insert(str.end(), ETL_OR_STD11::begin(i), ETL_OR_STD11::end(i));
249 template <
typename TIString>
251 const uint32_t fractional,
257 typedef typename TIString::value_type
type;
263 str.push_back(
type(
'.'));
268#if ETL_USING_64BIT_TYPES
272 template <
typename TIString>
274 const uint64_t fractional,
280 typedef typename TIString::value_type
type;
286 str.push_back(
type(
'.'));
295 template <
typename T,
typename TIString>
301 typedef typename TIString::iterator
iterator;
302 typedef typename TIString::value_type
type;
311 if (isnan(value) || isinf(value))
320#if ETL_NOT_USING_64BIT_TYPES
321 if (max_precision > 9)
333 uworkspace_t multiplier = 1U;
335 for (uint32_t i = 0U; i < fractional_format.
get_precision(); ++i)
341 T f_integral =
floor(etl::absolute(value));
342 uworkspace_t integral =
static_cast<uworkspace_t
>(f_integral);
345 uworkspace_t fractional =
static_cast<uworkspace_t
>(
round((etl::absolute(value) - f_integral) * multiplier));
348 if (fractional == multiplier)
363 template <
typename T,
typename TIString>
365 const uint32_t denominator_exponent,
368 const bool append =
false)
370 typedef typename TIString::iterator
iterator;
371 typedef typename TIString::value_type
type;
382 working_t denominator = 1U;
384 for (uint32_t i = 0U; i < denominator_exponent; ++i)
390 working_t abs_value = etl::absolute_unsigned(value);
393 const uint32_t& original_decimal_digits = denominator_exponent;
396 const uint32_t displayed_decimal_digits = (format.
get_precision() > original_decimal_digits) ? original_decimal_digits : format.
get_precision();
407 if (original_decimal_digits > displayed_decimal_digits)
410 uint32_t count = original_decimal_digits - fractional_format.
get_width();
413 uint32_t rounding = 5U;
420 abs_value += rounding;
424 working_t integral = abs_value / denominator;
425 working_t fractional = abs_value % denominator;
428 uint32_t count = original_decimal_digits - fractional_format.
get_width();
442 template <
typename TIString>
448 uintptr_t p =
reinterpret_cast<uintptr_t
>(value);
456 template <
typename TIString>
467 typename TIString::iterator start = str.end();
469 str.insert(str.end(), value.begin(), value.end());
477 template <
typename TSringView,
typename TIString>
488 typename TIString::iterator start = str.end();
490 str.insert(str.end(), value.begin(), value.end());
500 template <
typename TIString>
504 const bool append =
false)
514 template <
typename TIString>
518 const bool append =
false)
525#if ETL_USING_64BIT_TYPES
529 template <
typename T,
typename TIString>
532 !etl::is_one_of<T, int64_t, uint64_t>::value,
const TIString&>
::type
545 template <
typename T,
typename TIString>
548 etl::is_one_of<T, int64_t, uint64_t>::value,
const TIString&>
::type
559 template <
typename T,
typename TIString>
562 !etl::is_one_of<T, int64_t, uint64_t>::value,
const TIString&>
::type
575 template <
typename T,
typename TIString>
578 etl::is_one_of<T, int64_t, uint64_t>::value,
const TIString&>
::type
589 template <
typename T,
typename TIString>
604 template <
typename T,
typename TIString>
618 template <
typename T,
typename TIString>
619 typename etl::enable_if<etl::is_floating_point<T>::value,
const TIString&>::type
conditional
Definition type_traits_generator.h:1223
enable_if
Definition type_traits_generator.h:1254
is_same
Definition type_traits_generator.h:1104
make_unsigned
Definition type_traits_generator.h:1244
bitset_ext
Definition absolute.h:39
ETL_CONSTEXPR14 etl::enable_if< etl::is_specialization< TToDuration, etl::chrono::duration >::value, TToDuration >::type floor(const etl::chrono::duration< TRep, TPeriod > &d) ETL_NOEXCEPT
Rounds down a duration to the nearest lower precision.
Definition duration.h:643
etl::enable_if<!etl::is_same< T, etl::istring >::value &&!etl::is_same< T, etl::string_view >::value, constetl::istring & >::type to_string(const T value, etl::istring &str, bool append=false)
Definition to_string.h:50
ETL_CONSTEXPR14 etl::enable_if< etl::is_specialization< TToDuration, etl::chrono::duration >::value, TToDuration >::type round(const etl::chrono::duration< TRep, TPeriod > &d) ETL_NOEXCEPT
Definition duration.h:680
iterator
Definition iterator.h:399
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:70
void add_floating_point(const T value, TIString &str, const etl::basic_format_spec< TIString > &format, const bool append)
Helper function for floating point.
Definition to_string_helper.h:296
void add_string(const TIString &value, TIString &str, const etl::basic_format_spec< TIString > &format, const bool append)
Helper function for strings.
Definition to_string_helper.h:457
void add_integral_denominated(const T value, const uint32_t denominator_exponent, TIString &str, const etl::basic_format_spec< TIString > &format, const bool append=false)
Helper function for denominated integers.
Definition to_string_helper.h:364
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:227
void add_integral_and_fractional(const uint32_t integral, const uint32_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:250
const TIString & to_string(const bool value, TIString &str, const etl::basic_format_spec< TIString > &format, const bool append=false)
For booleans.
Definition to_string_helper.h:501
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:143
void add_string_view(const TSringView &value, TIString &str, const etl::basic_format_spec< TIString > &format, const bool append)
Helper function for string views.
Definition to_string_helper.h:478
void add_pointer(const volatile void *value, TIString &str, const etl::basic_format_spec< TIString > &format, const bool append)
Helper function for pointers.
Definition to_string_helper.h:443
void add_boolean(const bool value, TIString &str, const etl::basic_format_spec< TIString > &format, const bool append)
Helper function for booleans.
Definition to_string_helper.h:95