FastLED 3.10.6
Loading...
Searching...
No Matches

◆ format_arg() [6/7]

template<typename T>
fl::enable_if<!fl::is_pointer< T >::value &&(scalar_kind< T >::value< 0)>::type fl::printf_detail::format_arg ( sstream & stream,
const FormatSpec & spec,
const T & arg )

Definition at line 520 of file stdio.h.

520 {
522 bool is_numeric = false;
523
524 switch (spec.type) {
525 case 'd':
526 case 'i': {
528 result = "<type_error>";
529 break;
530 }
531 is_numeric = true;
532
533 // Convert to string
534 sstream temp;
535 temp << arg;
536 result = temp.str();
537
538 // Handle sign flags
539 bool is_negative = !result.empty() && result[0] == '-';
540 if (!is_negative) {
541 if (spec.show_sign) {
542 result = fl::string("+") + result;
543 } else if (spec.space_sign) {
544 result = fl::string(" ") + result;
545 }
546 }
547 break;
548 }
549
550 case 'u': {
552 result = "<type_error>";
553 break;
554 }
555 is_numeric = true;
556
557 // Convert to string
558 sstream temp;
559 temp << arg;
560 result = temp.str();
561 break;
562 }
563
564 case 'o': {
566 result = "<type_error>";
567 break;
568 }
569 is_numeric = true;
570
571 // Convert to octal
572 result = to_octal(arg);
573
574 // Alternate form: prefix with 0 (but not for zero itself)
575 if (spec.alt_form && arg != 0) {
576 result = fl::string("0") + result;
577 }
578 break;
579 }
580
581 case 'x': {
582 is_numeric = true;
583
584 // Convert to hex
585 result = fl::to_hex(arg, spec.uppercase);
586
587 // Alternate form: prefix with 0x or 0X
588 if (spec.alt_form && arg != 0) {
589 result = fl::string(spec.uppercase ? "0X" : "0x") + result;
590 }
591 break;
592 }
593
594 case 'f': {
596 result = "<type_error>";
597 break;
598 }
599 is_numeric = true;
600
601 if (spec.precision >= 0) {
602 result = format_float(static_cast<float>(arg), spec.precision);
603 } else {
604 sstream temp;
605 temp << static_cast<float>(arg);
606 result = temp.str();
607 }
608 break;
609 }
610
611 case 'c': {
613 result = "<type_error>";
614 break;
615 }
616
617 char ch = static_cast<char>(arg);
618 char temp_str[2] = {ch, '\0'};
619 result = temp_str;
620 break;
621 }
622
623 case 's': {
624 sstream temp;
625 temp << arg;
626 result = temp.str();
627 break;
628 }
629
630 default:
631 result = "<unknown_format>";
632 break;
633 }
634
635 // Apply width and padding
636 result = apply_width(result, spec, is_numeric);
637
638 // Output final result
639 stream << result;
640}
string str() const FL_NO_EXCEPT
Definition strstream.h:43
fl::string apply_width(const fl::string &str, const FormatSpec &spec, bool is_numeric=false) FL_NO_EXCEPT
Definition stdio.h:247
fl::string to_octal(T value) FL_NO_EXCEPT
Definition stdio.h:228
fl::string format_float(float value, int precision) FL_NO_EXCEPT
Definition stdio.h:341
fl::string to_hex(T value, bool uppercase=false, bool pad_to_width=false) FL_NO_EXCEPT
Convert an integer value to hexadecimal string representation.
Definition string.h:526
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31

References fl::printf_detail::FormatSpec::alt_form, apply_width(), fl::FL_NO_EXCEPT, format_float(), fl::printf_detail::FormatSpec::precision, fl::printf_detail::FormatSpec::show_sign, fl::printf_detail::FormatSpec::space_sign, fl::sstream::str(), fl::to_hex(), to_octal(), fl::printf_detail::FormatSpec::type, fl::printf_detail::FormatSpec::uppercase, fl::is_floating_point< T >::value, and fl::is_integral< T >::value.

+ Here is the call graph for this function: