|
|
|
@ -38,15 +38,15 @@ inline bool starts_with(const std::string &s, const std::string &prefix) { |
|
|
|
|
return s.compare(0, prefix.size(), prefix) == 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template<typename ... Args> |
|
|
|
|
inline std::string string_format( const std::string& format, Args ... args ) { |
|
|
|
|
size_t size = snprintf( nullptr, 0, format.c_str(), args ... ) + 1; |
|
|
|
|
std::unique_ptr<char[]> buf( new char[ size ] ); |
|
|
|
|
snprintf( buf.get(), size, format.c_str(), args ... ); |
|
|
|
|
return std::string( buf.get(), buf.get() + size - 1 ); |
|
|
|
|
template <typename... Args> |
|
|
|
|
inline std::string string_format(const std::string& format, Args... args) { |
|
|
|
|
size_t size = snprintf(nullptr, 0, format.c_str(), args...) + 1; |
|
|
|
|
std::unique_ptr<char[]> buf(new char[size]); |
|
|
|
|
snprintf(buf.get(), size, format.c_str(), args...); |
|
|
|
|
return std::string(buf.get(), buf.get() + size - 1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
inline std::string read_file(std::string fn) { |
|
|
|
|
inline std::string read_file(const std::string &fn) { |
|
|
|
|
std::ifstream t(fn); |
|
|
|
|
std::stringstream buffer; |
|
|
|
|
buffer << t.rdbuf(); |
|
|
|
|