MCPcopy Create free account
hub / github.com/MrKepzie/Natron / string string_format

Method string string_format

Engine/Log.cpp:43–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41#include "Global/GlobalDefines.h"
42
43NATRON_NAMESPACE_ENTER
44
45// see second answer of http://stackoverflow.com/questions/2342162/stdstring-formatting-like-sprintf
46static
47std::string
48string_format(const std::string fmt,
49 ...)
50{
51 int size = ( (int)fmt.size() ) * 2 + 50; // Use a rubric appropriate for your code
52 std::string str;
53 va_list ap;
54
55 while (1) { // Maximum two passes on a POSIX system...
56 str.resize(size);
57 va_start(ap, fmt);
58 int n = vsnprintf( (char *)str.data(), size, fmt.c_str(), ap );
59 va_end(ap);
60 if ( (n > -1) && (n < size) ) { // Everything worked
61 str.resize(n);
62
63 return str;
64 }
65 if (n > -1) { // Needed size returned
66 size = n + 1; // For null char
67 } else {
68 size *= 2; // Guess at a larger size (OS specific)
69 }
70 }
71
72 return str;
73}
74
75class LogPrivate
76{

Callers

nothing calls this directly

Calls 3

sizeMethod · 0.45
resizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected