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

◆ format_integral()

void fl::printf_detail::format_integral ( sstream & stream,
const FormatSpec & spec,
const ScalarArg & a )

Definition at line 93 of file stdio.cpp.hpp.

93 {
95 bool is_numeric = false;
96
97 switch (spec.type) {
98 case 'd':
99 case 'i': {
100 is_numeric = true;
101 sstream temp;
102 stream_integral(temp, a);
103 result = temp.str();
104
105 // Handle sign flags
106 bool is_negative = !result.empty() && result[0] == '-';
107 if (!is_negative) {
108 if (spec.show_sign) {
109 result = fl::string("+") + result;
110 } else if (spec.space_sign) {
111 result = fl::string(" ") + result;
112 }
113 }
114 break;
115 }
116
117 case 'u': {
118 is_numeric = true;
119 sstream temp;
120 stream_integral(temp, a);
121 result = temp.str();
122 break;
123 }
124
125 case 'o': {
126 is_numeric = true;
127 result = to_octal(a.u);
128 // Alternate form: prefix with 0 (but not for zero itself)
129 if (spec.alt_form && a.u != 0) {
130 result = fl::string("0") + result;
131 }
132 break;
133 }
134
135 case 'x': {
136 is_numeric = true;
137 // Mirrors fl::to_hex<T> for the original type.
138 const bool negative = a.s < 0;
139 const fl::u64 magnitude =
140 negative ? static_cast<fl::u64>(0) - a.u : a.u; // no INT64_MIN UB
142 magnitude,
143 static_cast<fl::detail::HexIntWidth>(a.size * 8),
144 negative, spec.uppercase, false);
145 if (spec.alt_form && a.u != 0) {
146 result = fl::string(spec.uppercase ? "0X" : "0x") + result;
147 }
148 break;
149 }
150
151 case 'f':
152 result = "<type_error>";
153 break;
154
155 case 'c': {
156 char temp_str[2] = {static_cast<char>(a.u), '\0'};
157 result = temp_str;
158 break;
159 }
160
161 case 's': {
162 sstream temp;
163 stream_integral(temp, a);
164 result = temp.str();
165 break;
166 }
167
168 default:
169 result = "<unknown_format>";
170 break;
171 }
172 emit_padded(stream, spec, result, is_numeric);
173}
string str() const FL_NO_EXCEPT
Definition strstream.h:43
fl::string hex(u64 value, HexIntWidth width, bool is_negative, bool uppercase, bool pad_to_width)
Internal hex conversion function (implementation in charconv.cpp)
HexIntWidth
Integer width classification for hex conversion.
Definition charconv.h:42
void stream_integral(sstream &temp, const ScalarArg &a) FL_NO_EXCEPT
Definition stdio.cpp.hpp:66
void emit_padded(sstream &stream, const FormatSpec &spec, const fl::string &result, bool is_numeric) FL_NO_EXCEPT
Definition stdio.cpp.hpp:84
fl::string to_octal(T value) FL_NO_EXCEPT
Definition stdio.h:228
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31

References fl::FL_NO_EXCEPT, fl::detail::hex(), fl::sstream::str(), and to_octal().

Referenced by format_scalar_arg().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: