- Restored in-depth checking inside string_to<T>. Under advice of Matteo some code is still commented, since we are not sure if it`s correct

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@947 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
elvez 2006-08-28 09:56:35 +00:00
parent 645156e62c
commit 1cdd2a6a9e
1 changed files with 30 additions and 1 deletions

View File

@ -46,8 +46,13 @@ namespace sgpem
T
string_to(const ustring& str) throw(domain_error)
{
if (tokenize(str).size() != 1)
throw domain_error(_("too few or too many tokens"));
istringstream iss(str);
T result;
iss.exceptions(ios_base::failbit | ios_base::badbit);
try
{
@ -58,6 +63,13 @@ namespace sgpem
throw domain_error(e.what());
}
// disable exceptions, otherwise peek() will throw them!
// how useless!!!
// iss.exceptions(ios_base::goodbit);
// if (iss.peek() != istringstream::traits_type::eof())
// throw domain_error(_("incorrect number format"));
return result;
}
@ -71,7 +83,24 @@ namespace sgpem
istringstream iss(str);
bool value;
iss >> value;
iss.exceptions(ios_base::failbit | ios_base::badbit);
try
{
iss >> boolalpha >> value;
}
catch (ios_base::failure e)
{
throw domain_error(e.what());
}
// disable exceptions, otherwise peek() will throw them!
// how useless!!!
// iss.exceptions(ios_base::goodbit);
// if (iss.peek() != istringstream::traits_type::eof())
// throw domain_error(_("incorrect boolean"));
return value;
}