MCPcopy Create free account
hub / github.com/DFHack/dfhack / format

Method format

plugins/manipulator.cpp:512–560  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

510 return NULL;
511 }
512 string format (T obj, string fmt)
513 {
514 string dest = "";
515 bool in_opt = false;
516 size_t i = 0;
517 while (i < fmt.size())
518 {
519 if (in_opt)
520 {
521 if (fmt[i] == '%')
522 {
523 // escape: %% -> %
524 in_opt = false;
525 dest.push_back('%');
526 i++;
527 }
528 else
529 {
530 string opt = grab_opt(fmt, i);
531 if (opt.size())
532 {
533 T_callback func = get_callback(opt);
534 if (func != NULL)
535 dest += func(obj);
536 i += opt.size();
537 in_opt = false;
538 if (i < fmt.size() && fmt[i] == '$')
539 // Allow $ to terminate format options
540 i++;
541 }
542 else
543 {
544 // Unrecognized format option; replace with original text
545 dest.push_back('%');
546 in_opt = false;
547 }
548 }
549 }
550 else
551 {
552 if (fmt[i] == '%')
553 in_opt = true;
554 else
555 dest.push_back(fmt[i]);
556 i++;
557 }
558 }
559 return dest;
560 }
561protected:
562 T_optlist opt_list;
563};

Callers 8

write_tool_docsFunction · 0.45
conf.pyFile · 0.45
check_fileFunction · 0.45
applyMethod · 0.45
parse_argsFunction · 0.45
make_labeled_paragraphFunction · 0.45
render_dfhack_keybindFunction · 0.45
init_tag_indicesFunction · 0.45

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected