FastLED 3.9.15
Loading...
Searching...
No Matches

◆ format_arg() [3/3]

template<typename T>
void fl::printf_detail::format_arg ( StrStream & stream,
const FormatSpec & spec,
const T & arg )

Definition at line 225 of file printf.h.

225 {
226 switch (spec.type) {
227 case 'd':
228 case 'i':
230 stream << arg;
231 } else {
232 stream << "<type_error>";
233 }
234 break;
235
236 case 'u':
238 // Convert unsigned manually since StrStream treats all as signed
239 unsigned int val = static_cast<unsigned int>(arg);
240 if (val == 0) {
241 stream << "0";
242 } else {
243 fl::string result;
244 while (val > 0) {
245 char digit = '0' + (val % 10);
246 char temp_str[2] = {digit, '\0'};
247 fl::string digit_str(temp_str);
248 fl::string temp = digit_str;
249 temp += result;
250 result = temp;
251 val /= 10;
252 }
253 stream << result;
254 }
255 } else {
256 stream << "<type_error>";
257 }
258 break;
259
260 case 'f':
262 if (spec.precision >= 0) {
263 stream << format_float(static_cast<float>(arg), spec.precision);
264 } else {
265 stream << arg;
266 }
267 } else {
268 stream << "<type_error>";
269 }
270 break;
271
272 case 'c':
274 char ch = static_cast<char>(arg);
275 // Convert char to string since StrStream treats char as number
276 char temp_str[2] = {ch, '\0'};
277 stream << temp_str;
278 } else {
279 stream << "<type_error>";
280 }
281 break;
282
283 case 'x':
284 stream << to_hex(arg, spec.uppercase);
285 break;
286
287 case 's':
288 stream << arg; // StrStream handles string conversion
289 break;
290
291 default:
292 stream << "<unknown_format>";
293 break;
294 }
295}
fl::enable_if< fl::is_integral< T >::value, fl::string >::type to_hex(T value, bool uppercase)
Definition printf.h:180
static constexpr bool value
static constexpr bool value

References fl::printf_detail::FormatSpec::precision, to_hex(), fl::printf_detail::FormatSpec::type, fl::printf_detail::FormatSpec::uppercase, fl::is_floating_point< T >::value, and fl::is_integral< T >::value.

Referenced by format_arg(), and format_impl().

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