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

◆ format_arg() [3/4]

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

Definition at line 364 of file stdio.h.

364 {
366 bool is_numeric = false;
367
368 switch (spec.type) {
369 case 'd':
370 case 'i': {
372 result = "<type_error>";
373 break;
374 }
375 is_numeric = true;
376
377 // Convert to string
378 sstream temp;
379 temp << arg;
380 result = temp.str();
381
382 // Handle sign flags
383 bool is_negative = !result.empty() && result[0] == '-';
384 if (!is_negative) {
385 if (spec.show_sign) {
386 result = fl::string("+") + result;
387 } else if (spec.space_sign) {
388 result = fl::string(" ") + result;
389 }
390 }
391 break;
392 }
393
394 case 'u': {
396 result = "<type_error>";
397 break;
398 }
399 is_numeric = true;
400
401 // Convert to string
402 sstream temp;
403 temp << arg;
404 result = temp.str();
405 break;
406 }
407
408 case 'o': {
410 result = "<type_error>";
411 break;
412 }
413 is_numeric = true;
414
415 // Convert to octal
416 result = to_octal(arg);
417
418 // Alternate form: prefix with 0 (but not for zero itself)
419 if (spec.alt_form && arg != 0) {
420 result = fl::string("0") + result;
421 }
422 break;
423 }
424
425 case 'x': {
426 is_numeric = true;
427
428 // Convert to hex
429 result = fl::to_hex(arg, spec.uppercase);
430
431 // Alternate form: prefix with 0x or 0X
432 if (spec.alt_form && arg != 0) {
433 result = fl::string(spec.uppercase ? "0X" : "0x") + result;
434 }
435 break;
436 }
437
438 case 'f': {
440 result = "<type_error>";
441 break;
442 }
443 is_numeric = true;
444
445 if (spec.precision >= 0) {
446 result = format_float(static_cast<float>(arg), spec.precision);
447 } else {
448 sstream temp;
449 temp << static_cast<float>(arg);
450 result = temp.str();
451 }
452 break;
453 }
454
455 case 'c': {
457 result = "<type_error>";
458 break;
459 }
460
461 char ch = static_cast<char>(arg);
462 char temp_str[2] = {ch, '\0'};
463 result = temp_str;
464 break;
465 }
466
467 case 's': {
468 sstream temp;
469 temp << arg;
470 result = temp.str();
471 break;
472 }
473
474 default:
475 result = "<unknown_format>";
476 break;
477 }
478
479 // Apply width and padding
480 result = apply_width(result, spec, is_numeric);
481
482 // Output final result
483 stream << result;
484}
string str() const FL_NOEXCEPT
Definition strstream.h:43
fl::string to_octal(T value) FL_NOEXCEPT
Definition stdio.h:201
fl::string format_float(float value, int precision) FL_NOEXCEPT
Definition stdio.h:282
fl::string apply_width(const fl::string &str, const FormatSpec &spec, bool is_numeric=false) FL_NOEXCEPT
Definition stdio.h:220
fl::string to_hex(T value, bool uppercase=false, bool pad_to_width=false) FL_NOEXCEPT
Convert an integer value to hexadecimal string representation.
Definition string.h:517
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31

References apply_width(), FL_NOEXCEPT, format_float(), fl::sstream::str(), fl::to_hex(), to_octal(), fl::fl::is_floating_point< T >::value, and fl::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: