MCPcopy Create free account
hub / github.com/KhronosGroup/Vulkan-ValidationLayers / VFormat

Function VFormat

layers/utils/text_utils.cpp:25–50  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23namespace text {
24
25std::string VFormat(const char* format, va_list argptr) {
26 // Counts actual characters. Null terminator is accounted separately.
27 const int initial_max_symbol_count = 1024;
28
29 // Use vector as the output buffer for c-style formatting routines.
30 // Do not write directly to std::string internal storage because its
31 // structure and null terminator convention is not standardized.
32 std::vector<char> buffer(initial_max_symbol_count + 1 /*null terminator*/);
33
34 // The va_list will be modified by the call to vsnprintf. Use a copy in case we need to try again.
35 va_list argptr2;
36 va_copy(argptr2, argptr);
37 const int symbol_count = vsnprintf(buffer.data(), buffer.size(), format, argptr2);
38 va_end(argptr2);
39
40 if (symbol_count < 0) {
41 assert(false && "unexpected vsnprintf error");
42 return {};
43 }
44 if (symbol_count > initial_max_symbol_count) {
45 buffer.resize(symbol_count + 1 /*null terminator*/);
46 vsnprintf(buffer.data(), buffer.size(), format, argptr);
47 }
48 std::string str(buffer.data());
49 return str;
50}
51
52std::string Format(const char* format, ...) {
53 va_list argptr;

Callers 2

FormatFunction · 0.85
LogMessageVaListMethod · 0.85

Calls 3

dataMethod · 0.45
sizeMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected