mirror of
https://github.com/znc/znc.git
synced 2026-03-28 17:42:41 +01:00
Format traffic stats to not show bytes, but stuff like KiB and MiB etc
This adds CString::ToByteStr() for such jobs! git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1038 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
19
String.cpp
19
String.cpp
@@ -852,6 +852,25 @@ CString CString::ToKBytes(double d) {
|
||||
return szRet;
|
||||
}
|
||||
|
||||
CString CString::ToByteStr(unsigned long long d) {
|
||||
const unsigned long long KiB = 1024;
|
||||
const unsigned long long MiB = KiB * 1024;
|
||||
const unsigned long long GiB = MiB * 1024;
|
||||
const unsigned long long TiB = GiB * 1024;
|
||||
|
||||
if (d > TiB) {
|
||||
return CString(d / (double) TiB) + " TiB";
|
||||
} else if (d > GiB) {
|
||||
return CString(d / (double) GiB) + " GiB";
|
||||
} else if (d > MiB) {
|
||||
return CString(d / (double) MiB) + " MiB";
|
||||
} else if (d > KiB) {
|
||||
return CString(d / (double) KiB) + " KiB";
|
||||
}
|
||||
|
||||
return CString(d) + " B";
|
||||
}
|
||||
|
||||
bool CString::ToBool() const { return (!Trim_n().Trim_n("0").empty() && Trim_n().CaseCmp("false") != 0); }
|
||||
short CString::ToShort() const { return strtoul(this->c_str(), (char**) NULL, 10); }
|
||||
unsigned short CString::ToUShort() const { return strtoul(this->c_str(), (char**) NULL, 10); }
|
||||
|
||||
Reference in New Issue
Block a user