mirror of
https://github.com/luanti-org/luanti.git
synced 2025-11-26 10:55:29 +01:00
Apply some refactoring/cleanup to mainly util functions
This commit is contained in:
@@ -9,27 +9,22 @@
|
||||
|
||||
static const char hex_chars[] = "0123456789abcdef";
|
||||
|
||||
static inline std::string hex_encode(const char *data, unsigned int data_size)
|
||||
static inline std::string hex_encode(std::string_view data)
|
||||
{
|
||||
std::string ret;
|
||||
ret.reserve(data_size * 2);
|
||||
|
||||
char buf2[3];
|
||||
buf2[2] = '\0';
|
||||
|
||||
for (unsigned int i = 0; i < data_size; i++) {
|
||||
unsigned char c = (unsigned char)data[i];
|
||||
buf2[0] = hex_chars[(c & 0xf0) >> 4];
|
||||
buf2[1] = hex_chars[c & 0x0f];
|
||||
ret.append(buf2);
|
||||
ret.reserve(data.size() * 2);
|
||||
for (unsigned char c : data) {
|
||||
ret.push_back(hex_chars[(c & 0xf0) >> 4]);
|
||||
ret.push_back(hex_chars[c & 0x0f]);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline std::string hex_encode(std::string_view data)
|
||||
static inline std::string hex_encode(const char *data, size_t data_size)
|
||||
{
|
||||
return hex_encode(data.data(), data.size());
|
||||
if (!data_size)
|
||||
return "";
|
||||
return hex_encode(std::string_view(data, data_size));
|
||||
}
|
||||
|
||||
static inline bool hex_digit_decode(char hexdigit, unsigned char &value)
|
||||
|
||||
Reference in New Issue
Block a user