mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-30 05:05:19 -05:00
Make links in About page actual hyperlinks
This commit is contained in:
@@ -6,6 +6,38 @@
|
||||
|
||||
namespace hex {
|
||||
|
||||
std::string to_string(u128 value) {
|
||||
char data[45] = { 0 };
|
||||
|
||||
u8 index = sizeof(data) - 2;
|
||||
while (value != 0 && index != 0) {
|
||||
data[index] = '0' + value % 10;
|
||||
value /= 10;
|
||||
index--;
|
||||
}
|
||||
|
||||
return std::string(data + index + 1);
|
||||
}
|
||||
|
||||
std::string to_string(s128 value) {
|
||||
char data[45] = { 0 };
|
||||
|
||||
u128 unsignedValue = value < 0 ? -value : value;
|
||||
|
||||
u8 index = sizeof(data) - 2;
|
||||
while (unsignedValue != 0 && index != 0) {
|
||||
data[index] = '0' + unsignedValue % 10;
|
||||
unsignedValue /= 10;
|
||||
index--;
|
||||
}
|
||||
|
||||
if (value < 0) {
|
||||
data[index] = '-';
|
||||
return std::string(data + index);
|
||||
} else
|
||||
return std::string(data + index + 1);
|
||||
}
|
||||
|
||||
std::string toByteString(u64 bytes) {
|
||||
double value = bytes;
|
||||
u8 unitIndex = 0;
|
||||
@@ -74,6 +106,39 @@ namespace hex {
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> splitString(std::string_view string, std::string_view delimiter) {
|
||||
size_t start = 0, end;
|
||||
std::string token;
|
||||
std::vector<std::string> res;
|
||||
|
||||
while ((end = string.find (delimiter, start)) != std::string::npos) {
|
||||
token = string.substr(start, end - start);
|
||||
start = end + delimiter.length();
|
||||
res.push_back(token);
|
||||
}
|
||||
|
||||
res.push_back(std::string(string.substr(start)));
|
||||
return res;
|
||||
}
|
||||
|
||||
std::string toEngineeringString(double value) {
|
||||
constexpr std::array prefixes = { "a", "f", "p", "n", "u", "m", "", "k", "M", "G", "T", "P", "E" };
|
||||
|
||||
int8_t prefixIndex = 6;
|
||||
|
||||
while (prefixIndex != 0 && prefixIndex != 12 && (value >= 1000 || value < 1) && value != 0) {
|
||||
if (value >= 1000) {
|
||||
value /= 1000;
|
||||
prefixIndex++;
|
||||
} else if (value < 1) {
|
||||
value *= 1000;
|
||||
prefixIndex--;
|
||||
}
|
||||
}
|
||||
|
||||
return std::to_string(value).substr(0, 5) + prefixes[prefixIndex];
|
||||
}
|
||||
|
||||
std::vector<u8> readFile(std::string_view path) {
|
||||
FILE *file = fopen(path.data(), "rb");
|
||||
|
||||
@@ -90,4 +155,18 @@ namespace hex {
|
||||
return result;
|
||||
}
|
||||
|
||||
void openWebpage(std::string_view url) {
|
||||
|
||||
#if defined(OS_WINDOWS)
|
||||
system(hex::format("start %s", url.data()).c_str());
|
||||
#elif defined(OS_MACOS)
|
||||
system(hex::format("open %s", url.data()).c_str())
|
||||
#elif defined(OS_LINUX)
|
||||
system(hex::format("xdg-open %s", url.data()).c_str())
|
||||
#else
|
||||
#warning "Unknown OS, can't open webpages"
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user