Add support for IEC and SI size units to wxFileName::GetHumanReadableSize().

Allow choosing the multiplier to use (1000 or 1024) and the names of the units
(SI or IEC). By default, still use traditional convention, i.e. multiplier of
1024 but SI unit names. This will probably need to be changed to use IEC units
in the future.

Also added unit test for this function.

Closes #10673.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63870 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2010-04-06 14:53:04 +00:00
parent 2028c33ab5
commit b2edb8f3c5
5 changed files with 151 additions and 44 deletions

View File

@@ -65,6 +65,15 @@ enum wxPathFormat
wxPATH_MAX // Not a valid value for specifying path format
};
// different convention that may be used with GetHumanReadableSize()
enum wxSizeConvention
{
wxSIZE_CONV_TRADIONAL, // 1024 bytes = 1 KB
wxSIZE_CONV_IEC, // 1024 bytes = 1 KiB
wxSIZE_CONV_SI // 1000 bytes = 1 KB
};
// the kind of normalization to do with the file name: these values can be
// or'd together to perform several operations at once
enum wxPathNormalize
@@ -540,11 +549,15 @@ public:
static wxULongLong GetSize(const wxString &file);
// returns the size in a human readable form
wxString GetHumanReadableSize(const wxString &nullsize = wxGetTranslation(wxT("Not available")),
int precision = 1) const;
static wxString GetHumanReadableSize(const wxULongLong &sz,
const wxString &nullsize = wxGetTranslation(wxT("Not available")),
int precision = 1);
wxString
GetHumanReadableSize(const wxString& nullsize = _("Not available"),
int precision = 1,
wxSizeConvention conv = wxSIZE_CONV_TRADIONAL) const;
static wxString
GetHumanReadableSize(const wxULongLong& sz,
const wxString& nullsize = _("Not available"),
int precision = 1,
wxSizeConvention conv = wxSIZE_CONV_TRADIONAL);
#endif // wxUSE_LONGLONG