Fix parsing unsigned numbers in wxIntegerValidatorBase
Use wxNumberFormatter::FromString() overload taking wxULongLong_t to allow parsing numbers greater than LLONG_MAX.
This commit is contained in:
@@ -303,7 +303,7 @@ protected:
|
|||||||
|
|
||||||
// Provide methods for wxNumValidator use.
|
// Provide methods for wxNumValidator use.
|
||||||
wxString ToString(LongestValueType value) const;
|
wxString ToString(LongestValueType value) const;
|
||||||
static bool FromString(const wxString& s, LongestValueType *value);
|
bool FromString(const wxString& s, LongestValueType *value) const;
|
||||||
|
|
||||||
void DoSetMin(LongestValueType min) { m_min = min; }
|
void DoSetMin(LongestValueType min) { m_min = min; }
|
||||||
LongestValueType DoGetMin() const { return m_min; }
|
LongestValueType DoGetMin() const { return m_min; }
|
||||||
|
@@ -234,9 +234,29 @@ wxString wxIntegerValidatorBase::ToString(LongestValueType value) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
wxIntegerValidatorBase::FromString(const wxString& s, LongestValueType *value)
|
wxIntegerValidatorBase::FromString(const wxString& s,
|
||||||
|
LongestValueType *value) const
|
||||||
{
|
{
|
||||||
return wxNumberFormatter::FromString(s, value);
|
if ( CanBeNegative() )
|
||||||
|
{
|
||||||
|
return wxNumberFormatter::FromString(s, value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Parse as unsigned to ensure we don't accept minus sign here.
|
||||||
|
#ifdef wxULongLong_t
|
||||||
|
wxULongLong_t uvalue;
|
||||||
|
#else
|
||||||
|
unsigned long uvalue;
|
||||||
|
#endif
|
||||||
|
if ( !wxNumberFormatter::FromString(s, &uvalue) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// This cast is lossless.
|
||||||
|
*value = static_cast<LongestValueType>(uvalue);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
Reference in New Issue
Block a user