MCPcopy Create free account
hub / github.com/FastLED/FastLED / format_impl

Function format_impl

src/fl/stl/format.h:368–434  ·  view source on GitHub ↗

Core formatting implementation

Source from the content-addressed store, hash-verified

366
367// Core formatting implementation
368inline fl::string format_impl(const char* fmt, const FormatArg* args, int num_args) {
369 fl::string result;
370 const char* p = fmt;
371 int auto_index = 0;
372
373 while (*p) {
374 if (*p == '{') {
375 if (*(p + 1) == '{') {
376 // Escaped {{
377 result.append('{');
378 p += 2;
379 continue;
380 }
381
382 ++p; // Skip '{'
383
384 // Parse argument index
385 int arg_index = -1;
386 if (*p >= '0' && *p <= '9') {
387 arg_index = 0;
388 while (*p >= '0' && *p <= '9') {
389 arg_index = arg_index * 10 + (*p - '0');
390 ++p;
391 }
392 } else {
393 arg_index = auto_index++;
394 }
395
396 // Parse format spec
397 FormatSpec spec;
398 if (*p == ':') {
399 ++p;
400 p = parse_format_spec(p, spec);
401 }
402
403 // Skip to '}'
404 while (*p && *p != '}') ++p;
405 if (*p == '}') ++p;
406
407 // Format the argument
408 if (arg_index >= 0 && arg_index < num_args) {
409 fl::string formatted = args[arg_index].format(spec);
410 apply_width_align(result, formatted, spec);
411 } else {
412 result.append("<out_of_range>");
413 }
414 } else if (*p == '}') {
415 if (*(p + 1) == '}') {
416 // Escaped }}
417 result.append('}');
418 p += 2;
419 } else {
420 result.append(*p++);
421 }
422 } else {
423 // Regular character - find next special char
424 const char* next = p;
425 while (*next && *next != '{' && *next != '}') {

Callers 1

formatFunction · 0.70

Calls 4

apply_width_alignFunction · 0.85
formatMethod · 0.80
parse_format_specFunction · 0.70
appendMethod · 0.45

Tested by

no test coverage detected