mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 05:27:41 -05:00
Implemented crude support for custom encodings via thingy files
Relevant issue: #26
This commit is contained in:
@@ -180,6 +180,23 @@ namespace hex {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
inline std::vector<u8> parseByteString(std::string_view string) {
|
||||
auto byteString = std::string(string);
|
||||
byteString.erase(std::remove(byteString.begin(), byteString.end(), ' '), byteString.end());
|
||||
|
||||
if ((byteString.length() % 2) != 0) return { };
|
||||
|
||||
std::vector<u8> result;
|
||||
for (u32 i = 0; i < byteString.length(); i += 2) {
|
||||
if (!std::isxdigit(byteString[i]) || !std::isxdigit(byteString[i + 1]))
|
||||
return { };
|
||||
|
||||
result.push_back(std::strtoul(byteString.substr(i, 2).c_str(), nullptr, 16));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
inline std::string toBinaryString(hex::integral auto number) {
|
||||
if (number == 0) return "0";
|
||||
|
||||
@@ -190,6 +207,23 @@ namespace hex {
|
||||
return result;
|
||||
}
|
||||
|
||||
inline void trimLeft(std::string &s) {
|
||||
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) {
|
||||
return !std::isspace(ch);
|
||||
}));
|
||||
}
|
||||
|
||||
inline void trimRight(std::string &s) {
|
||||
s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) {
|
||||
return !std::isspace(ch);
|
||||
}).base(), s.end());
|
||||
}
|
||||
|
||||
inline void trim(std::string &s) {
|
||||
trimLeft(s);
|
||||
trimRight(s);
|
||||
}
|
||||
|
||||
#define SCOPE_EXIT(func) ScopeExit TOKEN_CONCAT(scopeGuard, __COUNTER__)([&] { func })
|
||||
class ScopeExit {
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user