diff --git a/Utilities/Log.cpp b/Utilities/Log.cpp index a6b3319940..44ed7dedf7 100644 --- a/Utilities/Log.cpp +++ b/Utilities/Log.cpp @@ -237,16 +237,15 @@ LogChannel &LogManager::getChannel(LogType type) } void log_message(Log::LogType type, Log::LogSeverity sev, const char* text) +{ + log_message(type, sev, std::string(text)); +} + +void log_message(Log::LogType type, Log::LogSeverity sev, std::string text) { //another msvc bug makes this not work, uncomment this and delete everything else in this function when it's fixed //Log::LogManager::getInstance().log({logType, severity, text}) - Log::LogMessage msg{ type, sev, text }; - Log::LogManager::getInstance().log(msg); -} - -void log_message(Log::LogType type, Log::LogSeverity sev, const std::string& text) -{ - Log::LogMessage msg{ type, sev, text }; + Log::LogMessage msg{ type, sev, std::move(text) }; Log::LogManager::getInstance().log(msg); } diff --git a/Utilities/Log.h b/Utilities/Log.h index 2eaf876f27..d1710f05cf 100644 --- a/Utilities/Log.h +++ b/Utilities/Log.h @@ -127,7 +127,7 @@ static struct { inline operator Log::LogType() { return Log::LogType::ARMv7; } } static struct { inline operator Log::LogType() { return Log::LogType::TTY; } } TTY; void log_message(Log::LogType type, Log::LogSeverity sev, const char* text); -void log_message(Log::LogType type, Log::LogSeverity sev, const std::string& text); +void log_message(Log::LogType type, Log::LogSeverity sev, std::string text); template __noinline void log_message(Log::LogType type, Log::LogSeverity sev, const char* fmt, Targs... args) diff --git a/Utilities/StrFmt.cpp b/Utilities/StrFmt.cpp index dcd7214430..4c8c43cdf2 100644 --- a/Utilities/StrFmt.cpp +++ b/Utilities/StrFmt.cpp @@ -11,7 +11,7 @@ std::string u128::to_xyzw() const return fmt::Format("x: %g y: %g z: %g w: %g", _f[3], _f[2], _f[1], _f[0]); } -std::string fmt::detail::to_hex(u64 value, size_t count) +std::string fmt::to_hex(u64 value, size_t count) { assert(count - 1 < 16); count = std::max(count, 16 - cntlz64(value) / 4); @@ -26,6 +26,50 @@ std::string fmt::detail::to_hex(u64 value, size_t count) return std::string(res, count); } +std::string fmt::to_udec(u64 value) +{ + char res[20] = {}; + size_t first = sizeof(res); + + if (!value) + { + res[--first] = '0'; + } + + for (; value; value /= 10) + { + res[--first] = '0' + (value % 10); + } + + return std::string(&res[first], sizeof(res) - first); +} + +std::string fmt::to_sdec(s64 svalue) +{ + const bool sign = svalue < 0; + u64 value = sign ? -svalue : svalue; + + char res[20] = {}; + size_t first = sizeof(res); + + if (!value) + { + res[--first] = '0'; + } + + for (; value; value /= 10) + { + res[--first] = '0' + (value % 10); + } + + if (sign) + { + res[--first] = '-'; + } + + return std::string(&res[first], sizeof(res) - first); +} + size_t fmt::detail::get_fmt_start(const char* fmt, size_t len) { for (size_t i = 0; i < len; i++) diff --git a/Utilities/StrFmt.h b/Utilities/StrFmt.h index 8e19d8c5df..36a1ee4abb 100644 --- a/Utilities/StrFmt.h +++ b/Utilities/StrFmt.h @@ -173,10 +173,12 @@ namespace fmt return src; } + std::string to_hex(u64 value, size_t count = 1); + std::string to_udec(u64 value); + std::string to_sdec(s64 value); + namespace detail { - std::string to_hex(u64 value, size_t count = 1); - size_t get_fmt_start(const char* fmt, size_t len); size_t get_fmt_len(const char* fmt, size_t len); size_t get_fmt_precision(const char* fmt, size_t len); @@ -198,7 +200,7 @@ namespace fmt } else if (fmt[len - 1] == 'd') { - return std::to_string((u32)arg); + return to_udec(arg); } else { @@ -220,7 +222,7 @@ namespace fmt } else if (fmt[len - 1] == 'd') { - return std::to_string((u32)arg); + return to_udec(arg); } else { @@ -242,7 +244,7 @@ namespace fmt } else if (fmt[len - 1] == 'd') { - return std::to_string(arg); + return to_udec(arg); } else { @@ -264,7 +266,7 @@ namespace fmt } else if (fmt[len - 1] == 'd') { - return std::to_string(arg); + return to_udec(arg); } else { @@ -286,7 +288,7 @@ namespace fmt } else if (fmt[len - 1] == 'd') { - return std::to_string((s32)arg); + return to_sdec(arg); } else { @@ -308,7 +310,7 @@ namespace fmt } else if (fmt[len - 1] == 'd') { - return std::to_string((s32)arg); + return to_sdec(arg); } else { @@ -330,7 +332,7 @@ namespace fmt } else if (fmt[len - 1] == 'd') { - return std::to_string(arg); + return to_sdec(arg); } else { @@ -352,7 +354,7 @@ namespace fmt } else if (fmt[len - 1] == 'd') { - return std::to_string(arg); + return to_sdec(arg); } else { @@ -625,8 +627,8 @@ namespace fmt vm::psv::ref (fmt::unveil) (vm_ref.h) Supported formatting: - %d - decimal; only basic std::to_string() functionality - %x - hexadecimal; %.8x - hexadecimal with the precision (from .2 to .16) + %d - decimal; to_sdec() and to_udec() + %x - hexadecimal; to_hex(), %08x - hexadecimal with minimal length (from 02 to 016) %s - string; generates "true" or "false" for bool %f - floating point; only basic std::to_string() functionality