diff --git a/Utilities/StrFmt.cpp b/Utilities/StrFmt.cpp index 7618bb3aab..a3a5dff484 100644 --- a/Utilities/StrFmt.cpp +++ b/Utilities/StrFmt.cpp @@ -38,67 +38,67 @@ void fmt_class_string>::format(std::string& out, u64 arg) template<> void fmt_class_string::format(std::string& out, u64 arg) { - fmt::append(out, "0x%hhx", static_cast(arg)); + fmt::append(out, "%#hhx", static_cast(arg)); } template<> void fmt_class_string::format(std::string& out, u64 arg) { - fmt::append(out, "0x%hhx", static_cast(arg)); + fmt::append(out, "%#hhx", static_cast(arg)); } template<> void fmt_class_string::format(std::string& out, u64 arg) { - fmt::append(out, "0x%hhx", static_cast(arg)); + fmt::append(out, "%#hhx", static_cast(arg)); } template<> void fmt_class_string::format(std::string& out, u64 arg) { - fmt::append(out, "0x%hx", static_cast(arg)); + fmt::append(out, "%#hx", static_cast(arg)); } template<> void fmt_class_string::format(std::string& out, u64 arg) { - fmt::append(out, "0x%hx", static_cast(arg)); + fmt::append(out, "%#hx", static_cast(arg)); } template<> void fmt_class_string::format(std::string& out, u64 arg) { - fmt::append(out, "0x%x", static_cast(arg)); + fmt::append(out, "%#x", static_cast(arg)); } template<> void fmt_class_string::format(std::string& out, u64 arg) { - fmt::append(out, "0x%x", static_cast(arg)); + fmt::append(out, "%#x", static_cast(arg)); } template<> void fmt_class_string::format(std::string& out, u64 arg) { - fmt::append(out, "0x%lx", static_cast(arg)); + fmt::append(out, "%#lx", static_cast(arg)); } template<> void fmt_class_string::format(std::string& out, u64 arg) { - fmt::append(out, "0x%lx", static_cast(arg)); + fmt::append(out, "%#lx", static_cast(arg)); } template<> void fmt_class_string::format(std::string& out, u64 arg) { - fmt::append(out, "0x%llx", static_cast(arg)); + fmt::append(out, "%#llx", static_cast(arg)); } template<> void fmt_class_string::format(std::string& out, u64 arg) { - fmt::append(out, "0x%llx", static_cast(arg)); + fmt::append(out, "%#llx", static_cast(arg)); } template<> @@ -116,7 +116,7 @@ void fmt_class_string::format(std::string& out, u64 arg) template<> void fmt_class_string::format(std::string& out, u64 arg) { - out += arg ? "true" : "false"; // TODO? + out += arg ? "true" : "false"; } template<> @@ -166,24 +166,19 @@ struct fmt::cfmt_src return out.size() - start; } - // Returns type size (0 if unknown, pointer, assumed max) + // Returns type size (0 if unknown, pointer, unsigned, assumed max) std::size_t type(std::size_t extra) const { // Hack: use known function pointers to determine type #define TYPE(type)\ if (sup[extra].fmt_string == &fmt_class_string::format) return sizeof(type); - TYPE(char); - TYPE(schar); - TYPE(uchar); - TYPE(short); - TYPE(ushort); TYPE(int); - TYPE(uint); - TYPE(long); - TYPE(ulong); TYPE(llong); - TYPE(ullong); + TYPE(schar); + TYPE(short); + if (std::is_signed::value) TYPE(char); + TYPE(long); #undef TYPE diff --git a/Utilities/cfmt.h b/Utilities/cfmt.h index 4480eb4460..6573b8faa8 100644 --- a/Utilities/cfmt.h +++ b/Utilities/cfmt.h @@ -340,15 +340,15 @@ std::size_t cfmt_append(Dst& out, const Char* fmt, Src&& src) ctx.type = (u8)src.type(ctx.args); } - // Sign-extended argument expected: no special conversion + // Sign-extended argument expected const u64 val = src.template get(ctx.args); - const s64 sval = val; + const bool negative = ctx.type && static_cast(val) < 0; const std::size_t start = out.size(); if (!ctx.dot || ctx.prec) { - if (sval < 0) + if (negative) { out.push_back('-'); } @@ -361,7 +361,7 @@ std::size_t cfmt_append(Dst& out, const Char* fmt, Src&& src) out.push_back(' '); } - write_decimal(sval < 0 ? 0 - val : val, ctx.prec); + write_decimal(negative ? 0 - val : val, ctx.prec); } const std::size_t size2 = out.size() - start; @@ -371,7 +371,7 @@ std::size_t cfmt_append(Dst& out, const Char* fmt, Src&& src) // Add padding if necessary if (ctx.zeros && !ctx.left && !ctx.dot) { - out.insert(out.begin() + start + (sval < 0 || ctx.sign || ctx.space), ctx.width - size2, '0'); + out.insert(out.begin() + start + (negative || ctx.sign || ctx.space), ctx.width - size2, '0'); } else { @@ -402,6 +402,7 @@ std::size_t cfmt_append(Dst& out, const Char* fmt, Src&& src) ctx.type == 2 ? 0xffffull : ctx.type == 4 ? 0xffffffffull : 0xffffffffffffffffull; + // Trunc sign-extended signed types const u64 val = src.template get(ctx.args) & mask; const std::size_t start = out.size(); @@ -452,6 +453,7 @@ std::size_t cfmt_append(Dst& out, const Char* fmt, Src&& src) ctx.type == 2 ? 0xffffull : ctx.type == 4 ? 0xffffffffull : 0xffffffffffffffffull; + // Trunc sign-extended signed types const u64 val = src.template get(ctx.args) & mask; const std::size_t start = out.size(); @@ -509,6 +511,7 @@ std::size_t cfmt_append(Dst& out, const Char* fmt, Src&& src) ctx.type == 2 ? 0xffffull : ctx.type == 4 ? 0xffffffffull : 0xffffffffffffffffull; + // Trunc sign-extended signed types const u64 val = src.template get(ctx.args) & mask; const std::size_t start = out.size();