Embedded Template Library 1.0
Loading...
Searching...
No Matches
to_string_helper.h
Go to the documentation of this file.
1
2
3/******************************************************************************
4The MIT License(MIT)
5
6Embedded Template Library.
7https://github.com/ETLCPP/etl
8https://www.etlcpp.com
9
10Copyright(c) 2019 John Wellbelove
11
12Permission is hereby granted, free of charge, to any person obtaining a copy
13of this software and associated documentation files(the "Software"), to deal
14in the Software without restriction, including without limitation the rights
15to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16copies of the Software, and to permit persons to whom the Software is
17furnished to do so, subject to the following conditions :
18
19The above copyright notice and this permission notice shall be included in all
20copies or substantial portions of the Software.
21
22THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28SOFTWARE.
29******************************************************************************/
30
31#ifndef ETL_TO_STRING_HELPER_INCLUDED
32#define ETL_TO_STRING_HELPER_INCLUDED
33
35
36#include "../platform.h"
37#include "../absolute.h"
38#include "../algorithm.h"
40#include "../container.h"
41#include "../iterator.h"
42#include "../limits.h"
43#include "../math.h"
44#include "../negative.h"
45#include "../type_traits.h"
46
47#include <math.h>
48
49#if ETL_USING_STL && ETL_USING_CPP11
50 #include <iterator> // For std::begin, std::end and std::size
51#endif
52
53namespace etl
54{
55 namespace private_to_string
56 {
57#if ETL_NOT_USING_64BIT_TYPES
58 typedef int32_t workspace_t;
59 typedef uint32_t uworkspace_t;
60#else
61 typedef int64_t workspace_t;
62 typedef uint64_t uworkspace_t;
63#endif
64
65 //***************************************************************************
67 //***************************************************************************
68 template <typename TIString>
69 void add_alignment(TIString& str, typename TIString::iterator position, const etl::basic_format_spec<TIString>& format)
70 {
71 uint32_t length = static_cast<uint32_t>(etl::distance(position, str.end()));
72
73 if (length < format.get_width())
74 {
75 uint32_t fill_length = format.get_width() - length;
76
77 if (format.is_left())
78 {
79 // Insert fill characters on the right.
80 str.insert(str.end(), fill_length, format.get_fill());
81 }
82 else
83 {
84 // Insert fill characters on the left.
85 str.insert(position, fill_length, format.get_fill());
86 }
87 }
88 }
89
90 //***************************************************************************
92 //***************************************************************************
93 template <typename TIString>
94 void add_boolean(const bool value, TIString& str, const etl::basic_format_spec<TIString>& format, const bool append)
95 {
96 typedef typename TIString::value_type type;
97 typedef typename TIString::iterator iterator;
98
99 static const type t[] = {'t', 'r', 'u', 'e'};
100 static const type f[] = {'f', 'a', 'l', 's', 'e'};
101
102 if (!append)
103 {
104 str.clear();
105 }
106
107 iterator start = str.end();
108
109 if (format.is_boolalpha())
110 {
111 if (value)
112 {
113 str.insert(str.end(), ETL_OR_STD11::begin(t), ETL_OR_STD11::end(t));
114 }
115 else
116 {
117 str.insert(str.end(), ETL_OR_STD11::begin(f), ETL_OR_STD11::end(f));
118 }
119 }
120 else
121 {
122 if (value)
123 {
124 str.push_back(type('1'));
125 }
126 else
127 {
128 str.push_back(type('0'));
129 }
130 }
131
132 etl::private_to_string::add_alignment(str, start, format);
133 }
134
135 //***************************************************************************
137 //***************************************************************************
138 template <typename T, typename TIString>
139 void add_integral(T value, TIString& str, const etl::basic_format_spec<TIString>& format, bool append, const bool negative)
140 {
141 typedef typename TIString::value_type type;
142 typedef typename TIString::iterator iterator;
143
144 if (!append)
145 {
146 str.clear();
147 }
148
149 iterator start = str.end();
150
151 if (value == 0)
152 {
153 // If number is negative, append '-' (a negative zero might occur for
154 // fractional numbers > -1.0)
155 if ((format.get_base() == 10U) && negative)
156 {
157 str.push_back(type('-'));
158 }
159
160 str.push_back(type('0'));
161 }
162 else
163 {
164 // Extract the digits, in reverse order.
165 while (value != 0)
166 {
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());
171 }
172
173 // If number is negative, append '-'
174 if ((format.get_base() == 10U) && negative)
175 {
176 str.push_back(type('-'));
177 }
178
179 if (format.is_show_base())
180 {
181 switch (format.get_base())
182 {
183 case 2U:
184 {
185 str.push_back(format.is_upper_case() ? type('B') : type('b'));
186 str.push_back(type('0'));
187 break;
188 }
189
190 case 8U:
191 {
192 str.push_back(type('0'));
193 break;
194 }
195
196 case 16U:
197 {
198 str.push_back(format.is_upper_case() ? type('X') : type('x'));
199 str.push_back(type('0'));
200 break;
201 }
202
203 default:
204 {
205 break;
206 }
207 }
208 }
209
210 // Reverse the string we appended.
211 etl::reverse(start, str.end());
212 }
213
214 etl::private_to_string::add_alignment(str, start, format);
215 }
216
217 //***************************************************************************
219 //***************************************************************************
220 template <typename TIString>
221 void add_nan_inf(const bool not_a_number, const bool infinity, const bool is_negative, TIString& str,
223 {
224 typedef typename TIString::value_type type;
225
226 static const type nan_lower[] = {'n', 'a', 'n'};
227 static const type nan_upper[] = {'N', 'A', 'N'};
228 static const type inf_lower[] = {'i', 'n', 'f'};
229 static const type inf_upper[] = {'I', 'N', 'F'};
230
231 if (not_a_number)
232 {
233 if (format.is_upper_case())
234 {
235 str.insert(str.end(), ETL_OR_STD11::begin(nan_upper), ETL_OR_STD11::end(nan_upper));
236 }
237 else
238 {
239 str.insert(str.end(), ETL_OR_STD11::begin(nan_lower), ETL_OR_STD11::end(nan_lower));
240 }
241 }
242 else if (infinity)
243 {
244 if (is_negative)
245 {
246 str.push_back(type('-'));
247 }
248
249 if (format.is_upper_case())
250 {
251 str.insert(str.end(), ETL_OR_STD11::begin(inf_upper), ETL_OR_STD11::end(inf_upper));
252 }
253 else
254 {
255 str.insert(str.end(), ETL_OR_STD11::begin(inf_lower), ETL_OR_STD11::end(inf_lower));
256 }
257 }
258 }
259
260 //***************************************************************************
262 //***************************************************************************
263 template <typename TIString>
264 void add_integral_and_fractional(const uint32_t integral, const uint32_t fractional, TIString& str,
265 const etl::basic_format_spec<TIString>& integral_format,
266 const etl::basic_format_spec<TIString>& fractional_format, const bool negative)
267 {
268 typedef typename TIString::value_type type;
269
270 etl::private_to_string::add_integral(integral, str, integral_format, true, negative);
271
272 if (fractional_format.get_precision() > 0)
273 {
274 str.push_back(type('.'));
275 etl::private_to_string::add_integral(fractional, str, fractional_format, true, false);
276 }
277 }
278
279#if ETL_USING_64BIT_TYPES
280 //***************************************************************************
282 //***************************************************************************
283 template <typename TIString>
284 void add_integral_and_fractional(const uint64_t integral, const uint64_t fractional, TIString& str,
285 const etl::basic_format_spec<TIString>& integral_format,
286 const etl::basic_format_spec<TIString>& fractional_format, const bool negative)
287 {
288 typedef typename TIString::value_type type;
289
290 etl::private_to_string::add_integral(integral, str, integral_format, true, negative);
291
292 if (fractional_format.get_precision() > 0)
293 {
294 str.push_back(type('.'));
295 etl::private_to_string::add_integral(fractional, str, fractional_format, true, false);
296 }
297 }
298#endif
299
300 //***************************************************************************
302 //***************************************************************************
303 template <typename T, typename TIString>
304 void add_floating_point_scientific(const T value, TIString& str, const etl::basic_format_spec<TIString>& format, const uint32_t max_precision)
305 {
306 typedef typename TIString::value_type type;
307
308 const uint32_t requested_precision = format.get_precision();
309 const uint32_t precision = (requested_precision > max_precision) ? max_precision : requested_precision;
310
311 etl::basic_format_spec<TIString> mantissa_integral_format = format;
312 mantissa_integral_format.decimal().width(0U).precision(0U);
313
314 etl::basic_format_spec<TIString> mantissa_fractional_format = mantissa_integral_format;
315 mantissa_fractional_format.precision(precision).width(precision).fill(type('0')).right();
316
317 T abs_value = etl::absolute(value);
318
319 // Find exponent by iterative scaling
320 int32_t exponent = 0;
321 T scaled = abs_value;
322
323 if (scaled >= T(1))
324 {
325 // Scale down for values >= 1
326 while (scaled >= T(10))
327 {
328 scaled /= T(10);
329 ++exponent;
330 }
331 }
332 else if (scaled > T(0))
333 {
334 // Scale up for values < 1
335 while (scaled < T(1))
336 {
337 scaled *= T(10);
338 --exponent;
339 }
340 }
341
342 // Calculate the multiplier for the fractional part.
343 uworkspace_t multiplier = 1U;
344 for (uint32_t i = 0U; i < precision; ++i)
345 {
346 multiplier *= 10U;
347 }
348
349 // Find the integral part of the floating point
350 T f_integral = ::floor(scaled);
351 uworkspace_t integral = static_cast<uworkspace_t>(f_integral);
352
353 // Find the fractional part of the floating point.
354 uworkspace_t fractional = static_cast<uworkspace_t>(::round((scaled - f_integral) * multiplier));
355
356 // Check for a rounding carry to the integral.
357 if (fractional == multiplier)
358 {
359 ++integral;
360 fractional = 0U;
361
362 if (integral == 10U)
363 {
364 integral = 1U;
365 ++exponent;
366 }
367 }
368
369 etl::private_to_string::add_integral_and_fractional(integral, fractional, str, mantissa_integral_format, mantissa_fractional_format,
370 etl::is_negative(value));
371
372 // Append the exponent.
373 str.push_back(format.is_upper_case() ? type('E') : type('e'));
374 str.push_back((exponent < 0) ? type('-') : type('+'));
375
376 uworkspace_t abs_exponent = static_cast<uworkspace_t>(etl::absolute(exponent));
377
378 etl::basic_format_spec<TIString> exponent_format = format;
379 exponent_format.decimal().width(1U).precision(0U).right();
380
381 etl::private_to_string::add_integral(abs_exponent, str, exponent_format, true, false);
382 }
383
384 //***************************************************************************
386 //***************************************************************************
387 template <typename T, typename TIString>
388 void add_floating_point_non_scientific(const T value, TIString& str, const etl::basic_format_spec<TIString>& format, const uint32_t max_precision)
389 {
390 typedef typename TIString::value_type type;
391
392 etl::basic_format_spec<TIString> integral_format = format;
393 integral_format.decimal().width(0).precision(format.get_precision() > max_precision ? max_precision : format.get_precision());
394
395 etl::basic_format_spec<TIString> fractional_format = integral_format;
396 fractional_format.width(integral_format.get_precision()).fill(type('0')).right();
397
398 // Calculate the multiplier for the fractional part.
399 uworkspace_t multiplier = 1U;
400
401 for (uint32_t i = 0U; i < fractional_format.get_precision(); ++i)
402 {
403 multiplier *= 10U;
404 }
405
406 // Find the integral part of the floating point
407 T f_integral = ::floor(etl::absolute(value));
408 uworkspace_t integral = static_cast<uworkspace_t>(f_integral);
409
410 // Find the fractional part of the floating point.
411 uworkspace_t fractional = static_cast<uworkspace_t>(::round((etl::absolute(value) - f_integral) * multiplier));
412
413 // Check for a rounding carry to the integral.
414 if (fractional == multiplier)
415 {
416 ++integral;
417 fractional = 0U;
418 }
419
420 // Create the string.
421 etl::private_to_string::add_integral_and_fractional(integral, fractional, str, integral_format, fractional_format, etl::is_negative(value));
422 }
423
424 //***************************************************************************
426 //***************************************************************************
427 template <typename T, typename TIString>
428 void add_floating_point(const T value, TIString& str, const etl::basic_format_spec<TIString>& format, const bool append)
429 {
430 typedef typename TIString::iterator iterator;
431
432 if (!append)
433 {
434 str.clear();
435 }
436
437 iterator start = str.end();
438
439 if (isnan(value) || isinf(value))
440 {
441 etl::private_to_string::add_nan_inf(isnan(value), isinf(value), etl::is_negative(value), str, format);
442 }
443 else
444 {
445 // Make sure we format the two halves correctly.
446 uint32_t max_precision = etl::numeric_limits<T>::digits10;
447
448#if ETL_NOT_USING_64BIT_TYPES
449 if (max_precision > 9)
450 {
451 max_precision = 9;
452 }
453#endif
454
455 bool requires_scientific_form = format.is_scientific() || (etl::absolute(value) > static_cast<T>(etl::numeric_limits<uworkspace_t>::max()));
456
457 if (requires_scientific_form)
458 {
459 etl::private_to_string::add_floating_point_scientific(value, str, format, max_precision);
460 }
461 else
462 {
463 etl::private_to_string::add_floating_point_non_scientific(value, str, format, max_precision);
464 }
465 }
466
467 // Add alignment if necessary.
468 etl::private_to_string::add_alignment(str, start, format);
469 }
470
471 //***************************************************************************
473 //***************************************************************************
474 template <typename T, typename TIString>
475 void add_integral_denominated(const T value, const uint32_t denominator_exponent, TIString& str, const etl::basic_format_spec<TIString>& format,
476 const bool append = false)
477 {
478 typedef typename TIString::iterator iterator;
479 typedef typename TIString::value_type type;
480 typedef typename etl::make_unsigned<T>::type working_t;
481
482 if (!append)
483 {
484 str.clear();
485 }
486
487 iterator start = str.end();
488
489 // Calculate the denominator.
490 working_t denominator = 1U;
491
492 for (uint32_t i = 0U; i < denominator_exponent; ++i)
493 {
494 denominator *= 10U;
495 }
496
497 // Get the absolute value, taking care of minimum negative values.
498 working_t abs_value = etl::absolute_unsigned(value);
499
500 // Figure out how many decimal digits we have in the value.
501 const uint32_t& original_decimal_digits = denominator_exponent;
502
503 // How many decimal digits are we displaying.
504 const uint32_t displayed_decimal_digits = (format.get_precision() > original_decimal_digits) ? original_decimal_digits : format.get_precision();
505
506 // Format for the integral part.
507 etl::basic_format_spec<TIString> integral_format = format;
508 integral_format.decimal().width(0U);
509
510 // Format for the fractional part.
511 etl::basic_format_spec<TIString> fractional_format = integral_format;
512 fractional_format.precision(displayed_decimal_digits).width(displayed_decimal_digits).fill(type('0')).right();
513
514 // Do we need to check for rounding?
515 if (original_decimal_digits > displayed_decimal_digits)
516 {
517 // Which digit to adjust?
518 uint32_t count = original_decimal_digits - fractional_format.get_width();
519
520 // The 'round-away-from-zero' value.
521 uint32_t rounding = 5U;
522
523 while (count-- > 1U)
524 {
525 rounding *= 10U;
526 }
527
528 abs_value += rounding;
529 }
530
531 // Split the value into integral and fractional.
532 working_t integral = abs_value / denominator;
533 working_t fractional = abs_value % denominator;
534
535 // Move the fractional part to the right place.
536 uint32_t count = original_decimal_digits - fractional_format.get_width();
537 while (count-- > 0U)
538 {
539 fractional /= 10U;
540 }
541
542 // Create the string.
543 etl::private_to_string::add_integral_and_fractional(integral, fractional, str, integral_format, fractional_format, etl::is_negative(value));
544 etl::private_to_string::add_alignment(str, start, format);
545 }
546
547 //***************************************************************************
549 //***************************************************************************
550 template <typename TIString>
551 void add_pointer(const volatile void* value, TIString& str, const etl::basic_format_spec<TIString>& format, const bool append)
552 {
553 uintptr_t p = reinterpret_cast<uintptr_t>(value);
554
555 return etl::private_to_string::add_integral(p, str, format, append, false);
556 }
557
558 //***************************************************************************
560 //***************************************************************************
561 template <typename TIString>
562 void add_string(const TIString& value, TIString& str, const etl::basic_format_spec<TIString>& format, const bool append)
563 {
564 if (!append)
565 {
566 str.clear();
567 }
568
569 typename TIString::iterator start = str.end();
570
571 str.insert(str.end(), value.begin(), value.end());
572
573 etl::private_to_string::add_alignment(str, start, format);
574 }
575
576 //***************************************************************************
578 //***************************************************************************
579 template <typename TSringView, typename TIString>
580 void add_string_view(const TSringView& value, TIString& str, const etl::basic_format_spec<TIString>& format, const bool append)
581 {
582 if (!append)
583 {
584 str.clear();
585 }
586
587 typename TIString::iterator start = str.end();
588
589 str.insert(str.end(), value.begin(), value.end());
590
591 etl::private_to_string::add_alignment(str, start, format);
592 }
593
594 //*********************************************************************************************************
595
596 //***************************************************************************
598 //***************************************************************************
599 template <typename TIString>
600 const TIString& to_string(const bool value, TIString& str, const etl::basic_format_spec<TIString>& format, const bool append = false)
601 {
602 etl::private_to_string::add_boolean(value, str, format, append);
603
604 return str;
605 }
606
607 //***************************************************************************
609 //***************************************************************************
610 template <typename TIString>
611 const TIString& to_string(const volatile void* value, TIString& str, const etl::basic_format_spec<TIString>& format, const bool append = false)
612 {
613 etl::private_to_string::add_pointer(value, str, format, append);
614
615 return str;
616 }
617
618#if ETL_USING_64BIT_TYPES
619 //***************************************************************************
621 //***************************************************************************
622 template <typename T, typename TIString>
623 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,
624 const TIString&>::type
625 to_string(const T value, TIString& str, const etl::basic_format_spec<TIString>& format, const bool append = false)
626 {
627 typedef typename etl::conditional<etl::is_signed<T>::value, int32_t, uint32_t>::type type;
628
629 etl::private_to_string::add_integral(type(value), str, format, append, etl::is_negative(value));
630
631 return str;
632 }
633
634 //***************************************************************************
636 //***************************************************************************
637 template <typename T, typename TIString>
638 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,
639 const TIString&>::type
640 to_string(const T value, TIString& str, const etl::basic_format_spec<TIString>& format, const bool append = false)
641 {
642 etl::private_to_string::add_integral(value, str, format, append, etl::is_negative(value));
643
644 return str;
645 }
646
647 //***************************************************************************
649 //***************************************************************************
650 template <typename T, typename TIString>
651 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,
652 const TIString&>::type
653 to_string(const T value, uint32_t denominator_exponent, TIString& str, const etl::basic_format_spec<TIString>& format,
654 const bool append = false)
655 {
656 typedef typename etl::conditional<etl::is_signed<T>::value, int32_t, uint32_t>::type type;
657
658 etl::private_to_string::add_integral_denominated(type(value), denominator_exponent, str, format, append);
659
660 return str;
661 }
662
663 //***************************************************************************
665 //***************************************************************************
666 template <typename T, typename TIString>
667 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,
668 const TIString&>::type
669 to_string(const T value, uint32_t denominator_exponent, TIString& str, const etl::basic_format_spec<TIString>& format,
670 const bool append = false)
671 {
672 etl::private_to_string::add_integral_denominated(value, denominator_exponent, str, format, append);
673
674 return str;
675 }
676#else
677 //***************************************************************************
679 //***************************************************************************
680 template <typename T, typename TIString>
681 typename etl::enable_if<etl::is_integral<T>::value && !etl::is_same<T, bool>::value>::value,
682 const TIString& > ::type to_string(const T value, TIString& str, const etl::basic_format_spec<TIString>& format, const bool append = false)
683 {
684 typedef typename etl::conditional<etl::is_signed<T>::value, int32_t, uint32_t>::type type;
685
686 etl::private_to_string::add_integral(type(value), str, format, append, false);
687
688 return str;
689 }
690
691 //***************************************************************************
693 //***************************************************************************
694 template <typename T, typename TIString>
695 typename etl::enable_if<etl::is_integral<T>::value && !etl::is_same<T, bool>::value>::value,
696 const TIString& > ::type to_string(const T value, uint32_t denominator_exponent, TIString& str, const etl::basic_format_spec<TIString>& format,
697 const bool append = false)
698 {
699 etl::private_to_string::add_integral_denominated(type(value), denominator_exponent, str, format, append, false);
700
701 return str;
702 }
703#endif
704
705 //***************************************************************************
707 //***************************************************************************
708 template <typename T, typename TIString>
709 typename etl::enable_if<etl::is_floating_point<T>::value, const TIString&>::type
710 to_string(const T value, TIString& str, const etl::basic_format_spec<TIString>& format, const bool append = false)
711 {
712 etl::private_to_string::add_floating_point(value, str, format, append);
713
714 return str;
715 }
716 } // namespace private_to_string
717} // namespace etl
718
719#endif
basic_format_spec
Definition basic_format_spec.h:203
ETL_CONSTEXPR14 basic_format_spec & right() ETL_LVALUE_REF_QUALIFIER ETL_NOEXCEPT
Definition basic_format_spec.h:516
ETL_CONSTEXPR14 basic_format_spec & fill(typename TString::value_type c) ETL_LVALUE_REF_QUALIFIER ETL_NOEXCEPT
Definition basic_format_spec.h:462
ETL_CONSTEXPR uint32_t get_base() const ETL_NOEXCEPT
Gets the base.
Definition basic_format_spec.h:345
ETL_CONSTEXPR14 basic_format_spec & width(uint32_t w) ETL_LVALUE_REF_QUALIFIER ETL_NOEXCEPT
Definition basic_format_spec.h:381
ETL_CONSTEXPR bool is_show_base() const ETL_NOEXCEPT
Gets the show base flag.
Definition basic_format_spec.h:372
ETL_CONSTEXPR bool is_upper_case() const ETL_NOEXCEPT
Gets the upper case flag.
Definition basic_format_spec.h:453
ETL_CONSTEXPR14 basic_format_spec & precision(uint32_t p) ETL_LVALUE_REF_QUALIFIER ETL_NOEXCEPT
Definition basic_format_spec.h:408
ETL_CONSTEXPR bool is_scientific() const ETL_NOEXCEPT
Gets the scientific flag.
Definition basic_format_spec.h:588
ETL_CONSTEXPR bool is_left() const ETL_NOEXCEPT
Gets the left justify flag.
Definition basic_format_spec.h:507
ETL_CONSTEXPR TString::value_type get_fill() const ETL_NOEXCEPT
Gets the fill character.
Definition basic_format_spec.h:480
ETL_CONSTEXPR bool is_boolalpha() const ETL_NOEXCEPT
Gets the boolalpha flag.
Definition basic_format_spec.h:561
ETL_CONSTEXPR uint32_t get_width() const ETL_NOEXCEPT
Gets the width.
Definition basic_format_spec.h:399
ETL_CONSTEXPR14 basic_format_spec & decimal() ETL_LVALUE_REF_QUALIFIER ETL_NOEXCEPT
Definition basic_format_spec.h:312
ETL_CONSTEXPR uint32_t get_precision() const ETL_NOEXCEPT
Gets the precision.
Definition basic_format_spec.h:426
Definition limits.h:1714
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:482
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:428
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:562
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:475
void add_floating_point_non_scientific(const T value, TIString &str, const etl::basic_format_spec< TIString > &format, const uint32_t max_precision)
Helper function for floating point in non-scientific format.
Definition to_string_helper.h:388
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:264
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:600
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_nan_inf(const bool not_a_number, const bool infinity, const bool is_negative, TIString &str, const etl::basic_format_spec< TIString > &format)
Helper function for floating point nan and inf.
Definition to_string_helper.h:221
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:580
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:551
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
void add_floating_point_scientific(const T value, TIString &str, const etl::basic_format_spec< TIString > &format, const uint32_t max_precision)
Helper function for floating point in scientific format.
Definition to_string_helper.h:304