Revert "Do llformat even better!"
This reverts commit 4f87e82a19.
string::data can't be nonconst until C++17, maybe one day.
This commit is contained in:
@@ -37,24 +37,26 @@
|
|||||||
|
|
||||||
#include <cstdarg>
|
#include <cstdarg>
|
||||||
|
|
||||||
constexpr auto smallsize = 1024;
|
|
||||||
// common used function with va_list argument
|
// common used function with va_list argument
|
||||||
// wrapper for vsnprintf to be called from llformatXXX functions.
|
// wrapper for vsnprintf to be called from llformatXXX functions.
|
||||||
static void va_format(std::string& charvector, const char *fmt, va_list va)
|
static void va_format(std::string& out, const char *fmt, va_list va)
|
||||||
{
|
{
|
||||||
|
constexpr auto smallsize = 1024;
|
||||||
|
std::vector<char> charvector(smallsize); // Evolves into charveleon
|
||||||
va_list va2;
|
va_list va2;
|
||||||
va_copy(va2, va);
|
va_copy(va2, va);
|
||||||
const auto size = std::vsnprintf(charvector.data(), charvector.size(), fmt, va);
|
const auto size = std::vsnprintf(charvector.data(), charvector.size(), fmt, va);
|
||||||
if (size >= smallsize) // Evolve into charveleon
|
if (size >= smallsize)
|
||||||
{
|
{
|
||||||
charvector.resize(1+size); // Use the String Stone
|
charvector.resize(1+size); // Use the String Stone
|
||||||
std::vsnprintf(charvector.data(), charvector.size(), fmt, va2);
|
std::vsnprintf(charvector.data(), charvector.size(), fmt, va2);
|
||||||
}
|
}
|
||||||
|
out.assign(charvector.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string llformat(const char *fmt, ...)
|
std::string llformat(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
std::string res(smallsize, '\0');
|
std::string res;
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, fmt);
|
va_start(va, fmt);
|
||||||
va_format(res, fmt, va);
|
va_format(res, fmt, va);
|
||||||
@@ -64,7 +66,7 @@ std::string llformat(const char *fmt, ...)
|
|||||||
|
|
||||||
std::string llformat_to_utf8(const char *fmt, ...)
|
std::string llformat_to_utf8(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
std::string res(smallsize, '\0');
|
std::string res;
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, fmt);
|
va_start(va, fmt);
|
||||||
va_format(res, fmt, va);
|
va_format(res, fmt, va);
|
||||||
|
|||||||
Reference in New Issue
Block a user