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

Function stl_vsprintf

library/MiscUtils.cpp:177–197  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

175}
176
177std::string stl_vsprintf(const char *fmt, va_list args) {
178 /* Allow small (about single line) strings to be printed into stack memory
179 * with a call to vsnprintf.
180 */
181 std::array<char,128> buf;
182 va_list args2;
183 va_copy(args2, args);
184 int rsz = vsnprintf(&buf[0], buf.size(), fmt, args2);
185 va_end(args2);
186 if (rsz < 0)
187 return std::string(); /* Error occurred */
188 if (static_cast<unsigned>(rsz) < buf.size())
189 return std::string(&buf[0], rsz); /* Whole string fits to a single line buffer */
190 std::string rv;
191 // Allocate enough memory for the output and null termination
192 rv.resize(rsz);
193 rsz = vsnprintf(&rv[0], rv.size()+1, fmt, args);
194 if (rsz < static_cast<int>(rv.size()))
195 rv.resize(std::max(rsz,0));
196 return rv;
197}
198
199bool split_string(std::vector<std::string> *out,
200 const std::string &str, const std::string &separator, bool squash_empty)

Callers 1

stl_sprintfFunction · 0.85

Calls 2

sizeMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected