added: to misc:

void OnlyDigit(StringType & s, bool allow_comma = true)
       removes all non-digit characters from a string


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@818 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2012-03-11 16:21:52 +00:00
parent b7007da5a9
commit 0b528c7225
2 changed files with 52 additions and 16 deletions

View File

@ -622,11 +622,11 @@ std::wstring::size_type i;
}
bool IsEmailCorrectChar(wchar_t c)
{
bool correct = false;
bool IsEmailCorrectChar(wchar_t c)
{
bool correct = false;
const wchar_t * allowed_chars = L"@.!#$%&'*+-/=?^_`{|}~";
if( (c >= 'A' && c<='Z') ||
@ -646,12 +646,12 @@ bool correct = false;
}
}
}
return correct;
}
return correct;
}
bool ValidateEmail(const wchar_t * email)
{
int at = 0; // how many '@'
@ -674,13 +674,13 @@ bool ValidateEmail(const wchar_t * email)
return true;
}
bool ValidateEmail(const std::wstring & email)
{
return ValidateEmail(email.c_str());
}
return ValidateEmail(email.c_str());
}

View File

@ -258,6 +258,42 @@ void MaxSize(StringType & str, size_t max_size)
/*
this method removing all characters from given string
only digits are allowed and if allow_comma then one comma (or dot)
character is allowed
*/
template<class StringType>
void OnlyDigit(StringType & s, bool allow_comma = true)
{
typename StringType::size_type i;
bool was_comma = false;
if( s.empty() )
{
s = '0';
return;
}
for(i=0 ; i<s.size() ; )
{
if( (s[i]>='0' && s[i]<='9') ||
(allow_comma && !was_comma && (s[i]=='.' || s[i]==',')) )
{
if( s[i]=='.' || s[i]==',' )
was_comma = true;
i += 1;
}
else
{
s.erase(i, 1);
}
}
}
wchar_t ToSmall(wchar_t c);
void ToSmall(std::wstring & s);