Add support for long long to wxNumberFormatter.

It seems to make sense to allow using it for formatting and parsing long long
values as well as it can be done trivially using almost the same code as for
long.

It would be nice to support long double in a similar way but we don't wrap
C99 strtold() right now so it wouldn't be as simple, leave it for later.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66712 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2011-01-19 10:47:57 +00:00
parent 066e5e3fd2
commit f2a5052baa
3 changed files with 115 additions and 13 deletions

View File

@@ -94,10 +94,8 @@ bool wxNumberFormatter::GetThousandsSeparatorIfUsed(wxChar *sep)
// Conversion to string and helpers
// ----------------------------------------------------------------------------
wxString wxNumberFormatter::ToString(long val, int style)
wxString wxNumberFormatter::PostProcessIntString(wxString s, int style)
{
wxString s = wxString::Format("%ld", val);
if ( style & Style_WithThousandsSep )
AddThousandsSeparators(s);
@@ -107,6 +105,21 @@ wxString wxNumberFormatter::ToString(long val, int style)
return s;
}
wxString wxNumberFormatter::ToString(long val, int style)
{
return PostProcessIntString(wxString::Format("%ld", val), style);
}
#ifdef wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
wxString wxNumberFormatter::ToString(wxLongLong_t val, int style)
{
return PostProcessIntString(wxString::Format("%" wxLongLongFmtSpec "d", val),
style);
}
#endif // wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
wxString wxNumberFormatter::ToString(double val, int precision, int style)
{
const wxString fmt = wxString::Format("%%.%df", precision);
@@ -183,6 +196,16 @@ bool wxNumberFormatter::FromString(wxString s, long *val)
return s.ToLong(val);
}
#ifdef wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
bool wxNumberFormatter::FromString(wxString s, wxLongLong_t *val)
{
RemoveThousandsSeparators(s);
return s.ToLongLong(val);
}
#endif // wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
bool wxNumberFormatter::FromString(wxString s, double *val)
{
RemoveThousandsSeparators(s);