util: remove function to_hex (#22792)

old-commit-hash: ff33ca341382be19a4be9bd71b97af1b01b553c7
This commit is contained in:
Dean Lee
2021-11-04 23:18:01 +08:00
committed by GitHub
parent 72c892e014
commit 7ff2217c8b
4 changed files with 13 additions and 32 deletions
+6 -15
View File
@@ -194,22 +194,13 @@ float getenv(const char* key, float default_val) {
return val ? atof(val) : default_val;
}
std::string tohex(const uint8_t *buf, size_t buf_size) {
std::unique_ptr<char[]> hexbuf(new char[buf_size * 2 + 1]);
for (size_t i = 0; i < buf_size; i++) {
sprintf(&hexbuf[i * 2], "%02x", buf[i]);
std::string hexdump(const uint8_t* in, const size_t size) {
std::stringstream ss;
ss << std::hex << std::setfill('0');
for (size_t i = 0; i < size; i++) {
ss << std::setw(2) << static_cast<unsigned int>(in[i]);
}
hexbuf[buf_size * 2] = 0;
return std::string(hexbuf.get(), hexbuf.get() + buf_size * 2);
}
std::string hexdump(const std::string& in) {
std::stringstream ss;
ss << std::hex << std::setfill('0');
for (size_t i = 0; i < in.size(); i++) {
ss << std::setw(2) << static_cast<unsigned int>(static_cast<unsigned char>(in[i]));
}
return ss.str();
return ss.str();
}
std::string dir_name(std::string const &path) {
+1 -2
View File
@@ -66,8 +66,7 @@ std::string getenv(const char* key, const char* default_val = "");
int getenv(const char* key, int default_val);
float getenv(const char* key, float default_val);
std::string tohex(const uint8_t* buf, size_t buf_size);
std::string hexdump(const std::string& in);
std::string hexdump(const uint8_t* in, const size_t size);
std::string dir_name(std::string const& path);
// **** file fhelpers *****