31#ifndef ETL_TO_STRING_HELPER_INCLUDED
32#define ETL_TO_STRING_HELPER_INCLUDED
49#if ETL_USING_STL && ETL_USING_CPP11
55 namespace private_to_string
57#if ETL_NOT_USING_64BIT_TYPES
58 typedef int32_t workspace_t;
59 typedef uint32_t uworkspace_t;
61 typedef int64_t workspace_t;
62 typedef uint64_t uworkspace_t;
68 template <
typename TIString>
71 uint32_t length =
static_cast<uint32_t
>(etl::distance(position, str.end()));
75 uint32_t fill_length = format.
get_width() - length;
80 str.insert(str.end(), fill_length, format.
get_fill());
85 str.insert(position, fill_length, format.
get_fill());
93 template <
typename TIString>
96 typedef typename TIString::value_type
type;
97 typedef typename TIString::iterator
iterator;
99 static const type t[] = {
't',
'r',
'u',
'e'};
100 static const type f[] = {
'f',
'a',
'l',
's',
'e'};
113 str.insert(str.end(), ETL_OR_STD11::begin(t), ETL_OR_STD11::end(t));
117 str.insert(str.end(), ETL_OR_STD11::begin(f), ETL_OR_STD11::end(f));
124 str.push_back(
type(
'1'));
128 str.push_back(
type(
'0'));
138 template <
typename T,
typename TIString>
141 typedef typename TIString::value_type
type;
142 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)))
169 :
type(
'0' + remainder));
170 value = value / T(format.
get_base());
174 if ((format.
get_base() == 10U) && negative)
176 str.push_back(
type(
'-'));
186 str.push_back(
type(
'0'));
192 str.push_back(
type(
'0'));
199 str.push_back(
type(
'0'));
211 etl::reverse(start, str.end());
220 template <
typename TIString>
221 void add_nan_inf(
const bool not_a_number,
const bool infinity, TIString& str)
223 typedef typename TIString::value_type
type;
225 static const type n[] = {
'n',
'a',
'n'};
226 static const type i[] = {
'i',
'n',
'f'};
230 str.insert(str.end(), ETL_OR_STD11::begin(n), ETL_OR_STD11::end(n));
234 str.insert(str.end(), ETL_OR_STD11::begin(i), ETL_OR_STD11::end(i));
241 template <
typename TIString>
246 typedef typename TIString::value_type
type;
252 str.push_back(
type(
'.'));
257#if ETL_USING_64BIT_TYPES
261 template <
typename TIString>
266 typedef typename TIString::value_type
type;
272 str.push_back(
type(
'.'));
281 template <
typename T,
typename TIString>
284 typedef typename TIString::iterator
iterator;
285 typedef typename TIString::value_type
type;
294 if (isnan(value) || isinf(value))
303#if ETL_NOT_USING_64BIT_TYPES
304 if (max_precision > 9)
316 uworkspace_t multiplier = 1U;
318 for (uint32_t i = 0U; i < fractional_format.
get_precision(); ++i)
324 T f_integral =
::floor(etl::absolute(value));
325 uworkspace_t integral =
static_cast<uworkspace_t
>(f_integral);
328 uworkspace_t fractional =
static_cast<uworkspace_t
>(
::round((etl::absolute(value) - f_integral) * multiplier));
331 if (fractional == multiplier)
346 template <
typename T,
typename TIString>
348 const bool append =
false)
350 typedef typename TIString::iterator
iterator;
351 typedef typename TIString::value_type
type;
352 typedef typename etl::make_unsigned<T>::type working_t;
362 working_t denominator = 1U;
364 for (uint32_t i = 0U; i < denominator_exponent; ++i)
370 working_t abs_value = etl::absolute_unsigned(value);
373 const uint32_t& original_decimal_digits = denominator_exponent;
376 const uint32_t displayed_decimal_digits = (format.
get_precision() > original_decimal_digits) ? original_decimal_digits : format.
get_precision();
387 if (original_decimal_digits > displayed_decimal_digits)
390 uint32_t count = original_decimal_digits - fractional_format.
get_width();
393 uint32_t rounding = 5U;
400 abs_value += rounding;
404 working_t integral = abs_value / denominator;
405 working_t fractional = abs_value % denominator;
408 uint32_t count = original_decimal_digits - fractional_format.
get_width();
422 template <
typename TIString>
425 uintptr_t p =
reinterpret_cast<uintptr_t
>(value);
433 template <
typename TIString>
441 typename TIString::iterator start = str.end();
443 str.insert(str.end(), value.begin(), value.end());
451 template <
typename TSringView,
typename TIString>
459 typename TIString::iterator start = str.end();
461 str.insert(str.end(), value.begin(), value.end());
471 template <
typename TIString>
482 template <
typename TIString>
490#if ETL_USING_64BIT_TYPES
494 template <
typename T,
typename TIString>
495 typename etl::enable_if<etl::is_integral<T>::value && !etl::is_same<T, bool>::value && !etl::is_one_of<T, int64_t, uint64_t>::value,
499 typedef typename etl::conditional<etl::is_signed<T>::value, int32_t, uint32_t>
::type type;
509 template <
typename T,
typename TIString>
510 typename etl::enable_if<etl::is_integral<T>::value && !etl::is_same<T, bool>::value && etl::is_one_of<T, int64_t, uint64_t>::value,
522 template <
typename T,
typename TIString>
523 typename etl::enable_if<etl::is_integral<T>::value && !etl::is_same<T, bool>::value && !etl::is_one_of<T, int64_t, uint64_t>::value,
526 const bool append =
false)
528 typedef typename etl::conditional<etl::is_signed<T>::value, int32_t, uint32_t>
::type type;
538 template <
typename T,
typename TIString>
539 typename etl::enable_if<etl::is_integral<T>::value && !etl::is_same<T, bool>::value && etl::is_one_of<T, int64_t, uint64_t>::value,
542 const bool append =
false)
552 template <
typename T,
typename TIString>
553 typename etl::enable_if<etl::is_integral<T>::value && !etl::is_same<T, bool>::value>::value,
556 typedef typename etl::conditional<etl::is_signed<T>::value, int32_t, uint32_t>
::type type;
566 template <
typename T,
typename TIString>
567 typename etl::enable_if<etl::is_integral<T>::value && !etl::is_same<T, bool>::value>::value,
569 const bool append =
false)
580 template <
typename T,
typename TIString>
581 typename etl::enable_if<etl::is_floating_point<T>::value,
const TIString&>::type
bitset_ext
Definition absolute.h:40
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:630
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:665
iterator
Definition iterator.h:424
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:69
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:282
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:434
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:347
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:221
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:242
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:472
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:139
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:452
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:423
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:94