Line data Source code
1 : #ifndef THINGER_UTIL_HEX_HPP
2 : #define THINGER_UTIL_HEX_HPP
3 :
4 : #include <string>
5 : #include <sstream>
6 : #include <iomanip>
7 :
8 : namespace thinger {
9 : namespace util {
10 :
11 34 : inline std::string lowercase_hex_encode(const std::string& input) {
12 34 : std::ostringstream oss;
13 422 : for (unsigned char c : input) {
14 388 : oss << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(c);
15 : }
16 68 : return oss.str();
17 34 : }
18 :
19 : inline std::string uppercase_hex_encode(const std::string& input) {
20 : std::ostringstream oss;
21 : oss << std::uppercase;
22 : for (unsigned char c : input) {
23 : oss << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(c);
24 : }
25 : return oss.str();
26 : }
27 :
28 : } // namespace util
29 : } // namespace thinger
30 :
31 : #endif // THINGER_UTIL_HEX_HPP
|