mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-23 07:57:51 -05:00
get rid of strfmt and cstrfmt functions for being evil and redundant
This commit is contained in:
parent
dd62eac4c5
commit
b69ac71ede
1 changed files with 0 additions and 25 deletions
|
@ -71,31 +71,6 @@ namespace geode {
|
|||
return value < minValue ? minValue : maxValue < value ? maxValue : value;
|
||||
}
|
||||
|
||||
// from https://stackoverflow.com/questions/2342162/stdstring-formatting-like-sprintf
|
||||
template <typename... Args>
|
||||
std::string strfmt(std::string const& 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);
|
||||
auto buf = std::make_unique<char[]>(size);
|
||||
std::snprintf(buf.get(), size, format.c_str(), args...);
|
||||
return std::string(buf.get(), buf.get() + size - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a string
|
||||
* @returns Pointer to char array. MAKE SURE TO CALL DELETE[]!
|
||||
*/
|
||||
template <typename... Args>
|
||||
char const* cstrfmt(char const* fmt, Args... args) {
|
||||
auto str = strfmt(fmt, args...);
|
||||
char* ptr = new char[str.size() + 1];
|
||||
strcpy_s(ptr, str.c_str());
|
||||
return ptr;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::string intToHex(T i) {
|
||||
std::stringstream stream;
|
||||
|
|
Loading…
Reference in a new issue