sys: Replace printf formatting with libfmt

This commit is contained in:
WerWolv
2021-03-03 19:58:22 +01:00
parent 4e86d874a7
commit 188723e888
21 changed files with 108 additions and 107 deletions

View File

@@ -7,10 +7,10 @@ namespace hex {
namespace fs = std::filesystem;
// hex::plugin::<pluginName>::internal::initializePlugin()
constexpr auto InitializePluginSymbol = "_ZN3hex6plugin%d%s8internal16initializePluginEv";
constexpr auto GetPluginNameSymbol = "_ZN3hex6plugin%d%s8internal13getPluginNameEv";
constexpr auto GetPluginAuthorSymbol = "_ZN3hex6plugin%d%s8internal15getPluginAuthorEv";
constexpr auto GetPluginDescriptionSymbol = "_ZN3hex6plugin%d%s8internal20getPluginDescriptionEv";
constexpr auto InitializePluginSymbol = "_ZN3hex6plugin{0}{1}8internal16initializePluginEv";
constexpr auto GetPluginNameSymbol = "_ZN3hex6plugin{0}{1}8internal13getPluginNameEv";
constexpr auto GetPluginAuthorSymbol = "_ZN3hex6plugin{0}{1}8internal15getPluginAuthorEv";
constexpr auto GetPluginDescriptionSymbol = "_ZN3hex6plugin{0}{1}8internal20getPluginDescriptionEv";
Plugin::Plugin(std::string_view path) {
this->m_handle = dlopen(path.data(), RTLD_LAZY);
@@ -54,7 +54,7 @@ namespace hex {
if (this->m_getPluginNameFunction != nullptr)
return this->m_getPluginNameFunction();
else
return hex::format("Unknown Plugin @ 0x016llX", this->m_handle);
return hex::format("Unknown Plugin @ 0x{0:016X}", this->m_handle);
}
std::string Plugin::getPluginAuthor() const {

View File

@@ -71,7 +71,7 @@ namespace hex {
if (ImGui::CollapsingHeader((std::string(name.data()) + "###" + std::to_string((u64)comment.data())).c_str())) {
ImGui::TextUnformatted("hex.view.bookmarks.title.info"_lang);
ImGui::Separator();
ImGui::Text("hex.view.bookmarks.address"_lang, region.address, region.address + region.size - 1, region.size);
ImGui::TextUnformatted(hex::format("hex.view.bookmarks.address"_lang, region.address, region.address + region.size - 1, region.size).c_str());
{
u8 bytes[10] = { 0 };
@@ -79,7 +79,7 @@ namespace hex {
std::string bytesString;
for (u8 i = 0; i < std::min(region.size, size_t(10)); i++) {
bytesString += hex::format("%02X ", bytes[i]);
bytesString += hex::format("{0:02X} ", bytes[i]);
}
if (region.size > 10) {

View File

@@ -76,7 +76,7 @@ namespace hex {
disassembly.operators = instructions[instr].op_str;
for (u8 i = 0; i < instructions[instr].size; i++)
disassembly.bytes += hex::format("%02X ", instructions[instr].bytes[i]);
disassembly.bytes += hex::format("{0:02X} ", instructions[instr].bytes[i]);
disassembly.bytes.pop_back();
this->m_disassembly.push_back(disassembly);

View File

@@ -33,7 +33,7 @@ namespace hex {
ImGui::Text("ImHex Hex Editor v%s by WerWolv -", IMHEX_VERSION);
#if defined(GIT_BRANCH) && defined(GIT_COMMIT_HASH)
ImGui::SameLine();
if (ImGui::Hyperlink(hex::format("%s@%s", GIT_BRANCH, GIT_COMMIT_HASH).c_str()))
if (ImGui::Hyperlink(hex::format("{0}@{1}", GIT_BRANCH, GIT_COMMIT_HASH).c_str()))
hex::openWebpage("https://github.com/WerWolv/ImHex/commit/" GIT_COMMIT_HASH);
#endif
ImGui::TextUnformatted("hex.view.help.about.translator"_lang);
@@ -44,7 +44,7 @@ namespace hex {
hex::openWebpage("https://github.com/WerWolv/ImHex");
ImGui::NewLine();
ImGui::Text("hex.view.help.about.donations"_lang);
ImGui::TextUnformatted("hex.view.help.about.donations"_lang);
ImGui::Separator();
constexpr const char* Links[] = { "https://werwolv.net/donate", "https://www.patreon.com/werwolv", "https://github.com/sponsors/WerWolv" };

View File

@@ -211,7 +211,7 @@ namespace hex {
ImGui::SameLine();
ImGui::Spacing();
ImGui::SameLine();
ImGui::Text("hex.view.hexeditor.page"_lang, provider->getCurrentPage() + 1, provider->getPageCount());
ImGui::TextUnformatted(hex::format("hex.view.hexeditor.page"_lang, provider->getCurrentPage() + 1, provider->getPageCount()).c_str());
ImGui::SameLine();
if (ImGui::ArrowButton("prevPage", ImGuiDir_Left)) {
@@ -607,7 +607,7 @@ namespace hex {
std::string str;
for (const auto &byte : buffer)
str += hex::format("%02X ", byte);
str += hex::format("{0:02X} ", byte);
str.pop_back();
ImGui::SetClipboardText(str.c_str());
@@ -645,7 +645,7 @@ namespace hex {
str += "const unsigned char data[" + std::to_string(buffer.size()) + "] = { ";
for (const auto &byte : buffer)
str += hex::format("0x%02X, ", byte);
str += hex::format("0x{0:02X}, ", byte);
// Remove trailing comma
str.pop_back();
@@ -657,7 +657,7 @@ namespace hex {
str += "constexpr std::array<unsigned char, " + std::to_string(buffer.size()) + "> data = { ";
for (const auto &byte : buffer)
str += hex::format("0x%02X, ", byte);
str += hex::format("0x{0:02X}, ", byte);
// Remove trailing comma
str.pop_back();
@@ -669,7 +669,7 @@ namespace hex {
str += "final byte[] data = { ";
for (const auto &byte : buffer)
str += hex::format("0x%02X, ", byte);
str += hex::format("0x{0:02X}, ", byte);
// Remove trailing comma
str.pop_back();
@@ -681,7 +681,7 @@ namespace hex {
str += "const byte[] data = { ";
for (const auto &byte : buffer)
str += hex::format("0x%02X, ", byte);
str += hex::format("0x{0:02X}, ", byte);
// Remove trailing comma
str.pop_back();
@@ -693,7 +693,7 @@ namespace hex {
str += "let data: [u8, " + std::to_string(buffer.size()) + "] = [ ";
for (const auto &byte : buffer)
str += hex::format("0x%02X, ", byte);
str += hex::format("0x{0:02X}, ", byte);
// Remove trailing comma
str.pop_back();
@@ -705,7 +705,7 @@ namespace hex {
str += "data = bytes([ ";
for (const auto &byte : buffer)
str += hex::format("0x%02X, ", byte);
str += hex::format("0x{0:02X}, ", byte);
// Remove trailing comma
str.pop_back();
@@ -717,7 +717,7 @@ namespace hex {
str += "const data = new Uint8Array([ ";
for (const auto &byte : buffer)
str += hex::format("0x%02X, ", byte);
str += hex::format("0x{0:02X}, ", byte);
// Remove trailing comma
str.pop_back();
@@ -745,13 +745,13 @@ namespace hex {
for (u32 col = start >> 4; col <= (end >> 4); col++) {
str += hex::format("%08lX ", col << 4);
str += hex::format("{0:08X} ", col << 4);
for (u64 i = 0 ; i < 16; i++) {
if (col == (start >> 4) && i < (start & 0xF) || col == (end >> 4) && i > (end & 0xF))
str += " ";
else
str += hex::format("%02lX ", buffer[((col << 4) - start) + i]);
str += hex::format("{0:02X} ", buffer[((col << 4) - start) + i]);
if ((i & 0xF) == 0x7)
str += " ";
@@ -766,7 +766,7 @@ namespace hex {
else {
u8 c = buffer[((col << 4) - start) + i];
char displayChar = (c < 32 || c >= 128) ? '.' : c;
str += hex::format("%c", displayChar);
str += hex::format("{0}", displayChar);
}
}
@@ -804,13 +804,13 @@ R"(
for (u32 col = start >> 4; col <= (end >> 4); col++) {
str += hex::format(" <span class=\"offsetcolumn\">%08lX</span>&nbsp&nbsp<span class=\"hexcolumn\">", col << 4);
str += hex::format(" <span class=\"offsetcolumn\">{0:08X}</span>&nbsp&nbsp<span class=\"hexcolumn\">", col << 4);
for (u64 i = 0 ; i < 16; i++) {
if (col == (start >> 4) && i < (start & 0xF) || col == (end >> 4) && i > (end & 0xF))
str += "&nbsp&nbsp ";
else
str += hex::format("%02lX ", buffer[((col << 4) - start) + i]);
str += hex::format("{0:02X} ", buffer[((col << 4) - start) + i]);
if ((i & 0xF) == 0x7)
str += "&nbsp";
@@ -825,7 +825,7 @@ R"(
else {
u8 c = buffer[((col << 4) - start) + i];
char displayChar = (c < 32 || c >= 128) ? '.' : c;
str += hex::format("%c", displayChar);
str += hex::format("{0}", displayChar);
}
}