-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.cpp
More file actions
45 lines (35 loc) · 1.17 KB
/
utils.cpp
File metadata and controls
45 lines (35 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <utils.hpp>
//ONLY ASCII
//TODO : UTF-8~~
std::vector<std::string> WSVtoSV(const std::vector<std::wstring>& wvec) {
std::vector<std::string> result;
result.reserve(wvec.size());
for (const auto& wstr : wvec) {
result.push_back( std::string(wstr.begin(), wstr.end() ) );
}
return result;
}
std::string uint8toString(uint8_t * arr, size_t len) {
std::string result(reinterpret_cast<const char*>(arr), len);
return result;
}
std::vector<uint8_t> hexStringToByteArray(const std::string& hex) {
std::vector<uint8_t> bytes;
if (hex.length() % 2 != 0) {
throw std::invalid_argument("Hex string length must be even.");
}
for (size_t i = 0; i < hex.length(); i += 2) {
uint8_t byte = static_cast<uint8_t>(std::stoul(hex.substr(i, 2), nullptr, 16));
bytes.push_back(byte);
}
return bytes;
}
std::string bytesToHexString(const uint8_t* data, size_t length) {
char buffer[3]; // 2자리 HEX + 널 문자
std::string result;
for (size_t i = 0; i < length; i++) {
snprintf(buffer, sizeof(buffer), "%02X", data[i]); // 2자리 16진수 변환
result += buffer;
}
return result;
}