MCPcopy Index your code
hub / github.com/AppleWin/AppleWin / StrFormatV

Function StrFormatV

source/StrFormat.cpp:16–44  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14}
15
16std::string StrFormatV(const char* format, va_list va)
17{
18 size_t const bufsz_base = 2048; // Big enough for most cases.
19 char buf[bufsz_base];
20
21 // Need to call va_copy() so va can be used potentially for a second time.
22 // glibc on Linux *certainly* needs this while MSVC is fine without it though.
23 va_list va_copied;
24 va_copy(va_copied, va);
25 int len = vsnprintf(buf, sizeof(buf), format, va_copied);
26 va_end(va_copied);
27
28 if (len < 0)
29 {
30 return std::string(); // Error.
31 }
32 else if (size_t(len) < sizeof(buf))
33 {
34 return std::string(buf, size_t(len)); // No overflow.
35 }
36 else
37 {
38 // Overflow, need bigger buffer.
39 std::string s(size_t(len), '\0');
40 len = vsnprintf(&(*s.begin()), s.length() + 1, format, va);
41 assert(size_t(len) == s.length());
42 return s;
43 }
44}

Callers 9

LogOutputFunction · 0.85
StrFormatFunction · 0.85
ConsoleColorizePrintVaFunction · 0.85
ConsolePrintVaFunction · 0.85
ConsoleBufferPushVaFunction · 0.85
ConsoleDisplayErrorVaFunction · 0.85
ConsoleDisplayPushVaFunction · 0.85
FormatMethod · 0.85
PushLineFormatMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected