| 175 | } |
| 176 | |
| 177 | std::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 | |
| 199 | bool split_string(std::vector<std::string> *out, |
| 200 | const std::string &str, const std::string &separator, bool squash_empty) |
no test coverage detected