mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-01-31 04:25:40 +00:00
Added a very simplified implementation of std::format
This commit is contained in:
parent
9a78863f03
commit
4ffc5d6bf9
|
@ -19,6 +19,7 @@
|
|||
#include "utils/PlatformUtil.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdarg>
|
||||
#include <locale>
|
||||
|
||||
namespace Utils
|
||||
|
@ -626,6 +627,29 @@ namespace Utils
|
|||
return result;
|
||||
}
|
||||
|
||||
std::string format(const std::string stringArg, ...)
|
||||
{
|
||||
if (stringArg.empty())
|
||||
return "";
|
||||
|
||||
// Extract all the variadic function arguments.
|
||||
va_list args;
|
||||
va_list copy;
|
||||
|
||||
va_start(args, stringArg);
|
||||
va_copy(copy, args);
|
||||
|
||||
const int length {vsnprintf(nullptr, 0, &stringArg[0], copy)};
|
||||
std::string buffer(length, '\0');
|
||||
|
||||
vsnprintf(&buffer[0], length + 1, &stringArg[0], copy);
|
||||
|
||||
va_end(copy);
|
||||
va_end(args);
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
std::wstring stringToWideString(const std::string& stringArg)
|
||||
{
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> stringConverter;
|
||||
|
|
|
@ -35,6 +35,7 @@ namespace Utils
|
|||
std::string replace(const std::string& stringArg,
|
||||
const std::string& from,
|
||||
const std::string& to);
|
||||
std::string format(const std::string stringArg, ...);
|
||||
std::wstring stringToWideString(const std::string& stringArg);
|
||||
std::string wideStringToString(const std::wstring& stringArg);
|
||||
bool startsWith(const std::string& stringArg, const std::string& start);
|
||||
|
|
Loading…
Reference in a new issue