MCPcopy Create free account
hub / github.com/IppClub/Dora-SSR / sprintf

Function sprintf

Source/Common/Utils.cpp:204–234  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

202}
203
204std::string sprintf(const char* fmt, ...) {
205 int size = 1024;
206 std::vector<char> buffer(size);
207
208 va_list args;
209 va_start(args, fmt);
210 int n = vsnprintf(buffer.data(), size, fmt, args);
211 va_end(args);
212
213 if (n < 0) {
214 // vsnprintf failed
215 return "";
216 } else if (n < size) {
217 // formatted string successfully placed in buffer
218 return std::string(buffer.data(), n);
219 } else {
220 // buffer is not enough, need to reallocate
221 size = n + 1;
222 buffer.resize(size);
223
224 va_start(args, fmt);
225 n = vsnprintf(buffer.data(), size, fmt, args);
226 va_end(args);
227
228 if (n < 0 || n >= size) {
229 return "";
230 }
231
232 return std::string(buffer.data(), n);
233 }
234}
235
236NS_DORA_END

Callers 3

dir_iter_factoryFunction · 0.50
str_formatFunction · 0.50
luaO_pushvfstringFunction · 0.50

Calls 4

stringFunction · 0.85
vsnprintfFunction · 0.50
dataMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected