give better names to wxTextValidator::IsInCharIncludes and to wxTextValidator::IsNotInCharExcludes; add wxFILTER_SIMPLE_NUMBER style; remove specialized global helpers used by wxTextValidator in favour of wxStringCheck templated calls; better document the wxFILTER_* styles which use ctype standard functions
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58569 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -26,6 +26,7 @@ enum wxTextValidatorStyle
|
|||||||
wxFILTER_ASCII,
|
wxFILTER_ASCII,
|
||||||
wxFILTER_ALPHA,
|
wxFILTER_ALPHA,
|
||||||
wxFILTER_ALPHANUMERIC,
|
wxFILTER_ALPHANUMERIC,
|
||||||
|
wxFILTER_SIMPLE_NUMBER,
|
||||||
wxFILTER_NUMERIC,
|
wxFILTER_NUMERIC,
|
||||||
wxFILTER_INCLUDE_LIST,
|
wxFILTER_INCLUDE_LIST,
|
||||||
wxFILTER_EXCLUDE_LIST,
|
wxFILTER_EXCLUDE_LIST,
|
||||||
@@ -82,13 +83,13 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
|
|
||||||
// returns true if all characters of the given string are present in m_includes
|
// returns true if all characters of the given string are present in m_includes
|
||||||
bool IsInCharIncludes(const wxString& val) const;
|
bool ContainsOnlyIncludedCharacters(const wxString& val) const;
|
||||||
|
|
||||||
// returns true if all characters of the given string are NOT present in m_excludes
|
// returns true if all characters of the given string are NOT present in m_excludes
|
||||||
bool IsNotInCharExcludes(const wxString& val) const;
|
bool ContainsExcludedCharacters(const wxString& val) const;
|
||||||
|
|
||||||
// returns true if the contents of 'val' are valid for the current validation style
|
// returns true if the contents of 'val' are valid for the current validation style
|
||||||
bool IsValid(const wxString& val, wxString* errormsg) const;
|
virtual bool IsValid(const wxString& val, wxString* errormsg) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
wxTextValidatorStyle m_validatorStyle;
|
wxTextValidatorStyle m_validatorStyle;
|
||||||
|
@@ -15,16 +15,28 @@ enum wxTextValidatorStyle
|
|||||||
/// No filtering takes place.
|
/// No filtering takes place.
|
||||||
wxFILTER_NONE,
|
wxFILTER_NONE,
|
||||||
|
|
||||||
/// Non-ASCII characters are filtered out.
|
/// Non-ASCII characters are filtered out. See wxString::IsAscii.
|
||||||
wxFILTER_ASCII,
|
wxFILTER_ASCII,
|
||||||
|
|
||||||
/// Non-alpha characters are filtered out.
|
/// Non-alpha characters are filtered out.
|
||||||
|
/// Uses the wxWidgets wrapper for the standard CRT function @c isalpha
|
||||||
|
/// (which is locale-dependent) on all characters of the string.
|
||||||
wxFILTER_ALPHA,
|
wxFILTER_ALPHA,
|
||||||
|
|
||||||
/// Non-alphanumeric characters are filtered out.
|
/// Non-alphanumeric characters are filtered out.
|
||||||
|
/// Uses the wxWidgets wrapper for the standard CRT function @c isalnum
|
||||||
|
/// (which is locale-dependent) on all characters of the string.
|
||||||
wxFILTER_ALPHANUMERIC,
|
wxFILTER_ALPHANUMERIC,
|
||||||
|
|
||||||
/// Non-numeric characters are filtered out.
|
/// Non-numeric characters are filtered out.
|
||||||
|
/// Uses the wxWidgets wrapper for the standard CRT function @c isdigit
|
||||||
|
/// (which is locale-dependent) on all characters of the string.
|
||||||
|
wxFILTER_SIMPLE_NUMBER,
|
||||||
|
|
||||||
|
/// Non-numeric characters are filtered out.
|
||||||
|
/// Works like @c wxFILTER_SIMPLE_NUMBER but allows also decimal points,
|
||||||
|
/// minus/plus signs and the 'e' or 'E' character to input exponents.
|
||||||
|
/// Note that this is not the same behaviour of wxString::IsNumber().
|
||||||
wxFILTER_NUMERIC,
|
wxFILTER_NUMERIC,
|
||||||
|
|
||||||
/// Use an include list. The validator checks if the user input is on
|
/// Use an include list. The validator checks if the user input is on
|
||||||
|
@@ -37,43 +37,19 @@
|
|||||||
// global helpers
|
// global helpers
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
static bool wxIsAlpha(const wxString& val)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
for ( i = 0; i < (int)val.length(); i++)
|
|
||||||
{
|
|
||||||
if (!wxIsalpha(val[i]))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool wxIsAlphaNumeric(const wxString& val)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
for ( i = 0; i < (int)val.length(); i++)
|
|
||||||
{
|
|
||||||
if (!wxIsalnum(val[i]))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool wxIsNumeric(const wxString& val)
|
static bool wxIsNumeric(const wxString& val)
|
||||||
{
|
{
|
||||||
int i;
|
for ( wxString::const_iterator i = val.begin(); i != val.end(); ++i )
|
||||||
for ( i = 0; i < (int)val.length(); i++)
|
|
||||||
{
|
{
|
||||||
// Allow for "," (French) as well as "." -- in future we should
|
// Allow for "," (French) as well as "." -- in future we should
|
||||||
// use wxSystemSettings or other to do better localisation
|
// use wxSystemSettings or other to do better localisation
|
||||||
if ((!wxIsdigit(val[i])) && (val[i] != wxT('.')) && (val[i] != wxT(',')) && (val[i] != wxT('e')) &&
|
if ((!wxIsdigit(*i)) && (*i != wxT('.')) && (*i != wxT(',')) && (*i != wxT('e')) &&
|
||||||
(val[i] != wxT('E')) && (val[i] != wxT('+')) && (val[i] != wxT('-')))
|
(*i != wxT('E')) && (*i != wxT('+')) && (*i != wxT('-')))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxTextValidator
|
// wxTextValidator
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -234,27 +210,32 @@ bool wxTextValidator::IsValid(const wxString& val, wxString* pErr) const
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case wxFILTER_ALPHA:
|
case wxFILTER_ALPHA:
|
||||||
if ( !wxIsAlpha(val) )
|
if ( !wxStringCheck<wxIsalpha>(val) )
|
||||||
errormsg = _("'%s' should only contain alphabetic characters.");
|
errormsg = _("'%s' should only contain alphabetic characters.");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case wxFILTER_ALPHANUMERIC:
|
case wxFILTER_ALPHANUMERIC:
|
||||||
if ( !wxIsAlphaNumeric(val) )
|
if ( !wxStringCheck<wxIsalnum>(val) )
|
||||||
errormsg = _("'%s' should only contain alphabetic or numeric characters.");
|
errormsg = _("'%s' should only contain alphabetic or numeric characters.");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case wxFILTER_SIMPLE_NUMBER:
|
||||||
|
if ( !wxStringCheck<wxIsdigit>(val) )
|
||||||
|
errormsg = _("'%s' should be numeric.");
|
||||||
|
break;
|
||||||
|
|
||||||
case wxFILTER_NUMERIC:
|
case wxFILTER_NUMERIC:
|
||||||
if ( !wxIsNumeric(val) )
|
if ( !wxIsNumeric(val) )
|
||||||
errormsg = _("'%s' should be numeric.");
|
errormsg = _("'%s' should be numeric.");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case wxFILTER_INCLUDE_CHAR_LIST:
|
case wxFILTER_INCLUDE_CHAR_LIST:
|
||||||
if ( !IsInCharIncludes(val) )
|
if ( !ContainsOnlyIncludedCharacters(val) )
|
||||||
errormsg = _("'%s' is invalid");
|
errormsg = _("'%s' is invalid");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case wxFILTER_EXCLUDE_CHAR_LIST:
|
case wxFILTER_EXCLUDE_CHAR_LIST:
|
||||||
if ( !IsNotInCharExcludes(val) )
|
if ( ContainsExcludedCharacters(val) )
|
||||||
errormsg = _("'%s' is invalid");
|
errormsg = _("'%s' is invalid");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -268,7 +249,7 @@ bool wxTextValidator::IsValid(const wxString& val, wxString* pErr) const
|
|||||||
return errormsg.empty();
|
return errormsg.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxTextValidator::IsInCharIncludes(const wxString& val) const
|
bool wxTextValidator::ContainsOnlyIncludedCharacters(const wxString& val) const
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < val.length(); i++)
|
for (size_t i = 0; i < val.length(); i++)
|
||||||
if (m_includes.Index((wxString) val[i]) == wxNOT_FOUND)
|
if (m_includes.Index((wxString) val[i]) == wxNOT_FOUND)
|
||||||
@@ -279,7 +260,7 @@ bool wxTextValidator::IsInCharIncludes(const wxString& val) const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxTextValidator::IsNotInCharExcludes(const wxString& val) const
|
bool wxTextValidator::ContainsExcludedCharacters(const wxString& val) const
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < val.length(); i++)
|
for (size_t i = 0; i < val.length(); i++)
|
||||||
if (m_excludes.Index((wxString) val[i]) != wxNOT_FOUND)
|
if (m_excludes.Index((wxString) val[i]) != wxNOT_FOUND)
|
||||||
|
Reference in New Issue
Block a user