mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Create utility function for formatting bytes
Byte count to prettified representation as string.
This commit is contained in:
parent
de26e5735f
commit
eb14469178
@ -82,6 +82,7 @@ void PrintM128i64(__m128i in);
|
||||
void AppendPrintf(char* pBuffer, size_t nBufSize, char const* pFormat, ...);
|
||||
string PrintPercentageEscape(const string& svInput);
|
||||
|
||||
string FormatBytes(size_t nBytes);
|
||||
string FormatV(const char* szFormat, va_list args);
|
||||
string Format(const char* szFormat, ...);
|
||||
|
||||
|
@ -987,6 +987,18 @@ string PrintPercentageEscape(const string& svInput)
|
||||
return result;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// For formatting a STL string to a prettified representation of input bytes.
|
||||
string FormatBytes(size_t nBytes)
|
||||
{
|
||||
char szBuf[128] = "";
|
||||
const char* szPrefix[] = { "B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB" };
|
||||
const int iBase = 1024;
|
||||
size_t c = (std::min)((size_t)(log((double)nBytes) / log((double)iBase)), (size_t)sizeof(szPrefix) - 1);
|
||||
sprintf(szBuf, "%1.2lf %s", nBytes / pow((double)iBase, c), szPrefix[c]);
|
||||
return string(szBuf);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// For formatting a STL string using C-style format specifiers (va_list version).
|
||||
string FormatV(const char* szFormat, va_list args)
|
||||
|
Loading…
x
Reference in New Issue
Block a user