mirror of
https://github.com/Ryuzaki-MrL/savemii.git
synced 2026-03-28 04:56:17 -05:00
20 lines
774 B
C++
20 lines
774 B
C++
#include "savemng.h"
|
|
#include <cstdarg>
|
|
#include <memory>
|
|
#include <stdexcept>
|
|
#include <string>
|
|
|
|
bool replace(std::string &str, const std::string &from, const std::string &to);
|
|
std::string decodeXMLEscapeLine(std::string xmlString);
|
|
|
|
template<typename ... Args>
|
|
std::string string_format( const std::string& format, Args ... args )
|
|
{
|
|
int size_s = std::snprintf( nullptr, 0, format.c_str(), args ... ) + 1; // Extra space for '\0'
|
|
if( size_s <= 0 ){ throw std::runtime_error( "Error during formatting." ); }
|
|
auto size = static_cast<size_t>( size_s );
|
|
std::unique_ptr<char[]> buf( new char[ size ] );
|
|
std::snprintf( buf.get(), size, format.c_str(), args ... );
|
|
return std::string( buf.get(), buf.get() + size - 1 ); // We don't want the '\0' inside
|
|
}
|