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

◆ format_impl()

fl::string fl::format_detail::format_impl ( const char * fmt,
const FormatArg * args,
int num_args )
inline

Definition at line 368 of file format.h.

368 {
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 != '}') {
426 ++next;
427 }
428 result.append(p, static_cast<fl::size>(next - p));
429 p = next;
430 }
431 }
432
433 return result;
434}
void apply_width_align(fl::string &result, const fl::string &value, const FormatSpec &spec)
Definition format.h:121
const char * parse_format_spec(const char *p, FormatSpec &spec)
Definition format.h:66
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31
corkscrew_args args
Definition old.h:149

References apply_width_align(), args, and parse_format_spec().

Referenced by fl::format(), and fl::format().

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