#ifndef UTILPP_H #define UTILPP_H #include #include #include #include #include #include namespace util { inline bool starts_with(std::string s, std::string prefix) { return s.compare(0, prefix.size(), prefix) == 0; } template 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 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) { std::ifstream t(fn); std::stringstream buffer; buffer << t.rdbuf(); return buffer.str(); } inline std::string tohex(const uint8_t* buf, size_t buf_size) { std::unique_ptr hexbuf(new char[buf_size*2+1]); for (int i=0; i