1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 10:42:36 +01:00

fmt::to_udec(), fmt::to_sdec()

This commit is contained in:
Nekotekina 2015-01-19 16:31:02 +03:00
parent 0d28f378a7
commit 3428499492
4 changed files with 66 additions and 21 deletions

View File

@ -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);
}

View File

@ -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<typename... Targs>
__noinline void log_message(Log::LogType type, Log::LogSeverity sev, const char* fmt, Targs... args)

View File

@ -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<u64>(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++)

View File

@ -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