MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / formatStringImpl

Function formatStringImpl

src/OpenLoco/src/Localisation/Formatting.cpp:588–636  ·  view source on GitHub ↗

0x004958C6

Source from the content-addressed store, hash-verified

586
587 // 0x004958C6
588 static void formatStringImpl(StringBuffer& buffer, StringId id, FormatArgumentsView& args)
589 {
590 if (id < kUserStringsStart)
591 {
592 const char* sourceStr = getString(id);
593 if (sourceStr == nullptr)
594 {
595 buffer.format(std::locale(), "(missing string id: {})", id);
596 Logging::warn("formatString: nullptr for string id: {}", id);
597 return;
598 }
599
600 formatStringPart(buffer, sourceStr, args);
601 }
602 else if (id < kUserStringsEnd)
603 {
604 id -= kUserStringsStart;
605 args.skip<uint16_t>();
606 const char* sourceStr = getUserString(id);
607
608 buffer.append(sourceStr, kUserStringSize);
609 }
610 else if (id < kTownNamesEnd)
611 {
612 id -= kTownNamesStart;
613
614 const auto townId = TownId(args.pop<uint16_t>());
615 auto town = TownManager::get(townId);
616
617 // TODO: Clean this up once we have only FormatArguments.
618 FormatArgumentsBuffer buf;
619 auto fmt = FormatArguments(buf);
620 fmt.push(town->name);
621
622 auto fmtView = FormatArgumentsView(fmt);
623 formatStringImpl(buffer, id, fmtView);
624 }
625 else if (id == kTownNamesEnd)
626 {
627 const auto townId = TownId(args.pop<uint16_t>());
628 auto town = TownManager::get(townId);
629 formatString(buffer, town->name);
630 }
631 else
632 {
633 buffer.format(std::locale(), "(invalid string id: {})", id);
634 Logging::warn("formatString: invalid string id: {}", id);
635 }
636 }
637
638 static void formatString(StringBuffer& buffer, StringId id)
639 {

Callers 2

formatStringPartFunction · 0.85
formatStringFunction · 0.85

Calls 12

getStringFunction · 0.85
warnFunction · 0.85
formatStringPartFunction · 0.85
getUserStringFunction · 0.85
TownIdEnum · 0.85
FormatArgumentsViewClass · 0.85
formatStringFunction · 0.85
formatMethod · 0.80
appendMethod · 0.80
getFunction · 0.50
FormatArgumentsClass · 0.50
pushMethod · 0.45

Tested by

no test coverage detected