- Bullet-proofed the code in string_utils. Not tested for booleans, but don`t complain for the last test, it`s necessary, trust me.
git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@955 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
73c66c12d3
commit
2497aa3bc6
|
@ -46,10 +46,12 @@ namespace sgpem
|
||||||
T
|
T
|
||||||
string_to(const ustring& str) throw(domain_error)
|
string_to(const ustring& str) throw(domain_error)
|
||||||
{
|
{
|
||||||
if (tokenize(str).size() != 1)
|
Tokens tokens = tokenize(str);
|
||||||
|
|
||||||
|
if (tokens.size() != 1)
|
||||||
throw domain_error(_("too few or too many tokens"));
|
throw domain_error(_("too few or too many tokens"));
|
||||||
|
|
||||||
istringstream iss(str);
|
istringstream iss(tokens[0]);
|
||||||
T result;
|
T result;
|
||||||
|
|
||||||
iss.exceptions(ios_base::failbit | ios_base::badbit);
|
iss.exceptions(ios_base::failbit | ios_base::badbit);
|
||||||
|
@ -65,10 +67,10 @@ namespace sgpem
|
||||||
|
|
||||||
// disable exceptions, otherwise peek() will throw them!
|
// disable exceptions, otherwise peek() will throw them!
|
||||||
// how useless!!!
|
// how useless!!!
|
||||||
// iss.exceptions(ios_base::goodbit);
|
iss.exceptions(ios_base::goodbit);
|
||||||
|
|
||||||
// if (iss.peek() != istringstream::traits_type::eof())
|
if (iss.peek() != istringstream::traits_type::eof())
|
||||||
// throw domain_error(_("incorrect number format"));
|
throw domain_error(_("incorrect number format"));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -78,10 +80,12 @@ namespace sgpem
|
||||||
SG_DLLEXPORT bool
|
SG_DLLEXPORT bool
|
||||||
string_to<bool>(const Glib::ustring& str) throw(domain_error)
|
string_to<bool>(const Glib::ustring& str) throw(domain_error)
|
||||||
{
|
{
|
||||||
if (tokenize(str).size() != 1)
|
Tokens tokens = tokenize(str);
|
||||||
|
|
||||||
|
if (tokens.size() != 1)
|
||||||
throw domain_error(_("too few or too many tokens"));
|
throw domain_error(_("too few or too many tokens"));
|
||||||
|
|
||||||
istringstream iss(str);
|
istringstream iss(tokens[0]);
|
||||||
bool value;
|
bool value;
|
||||||
|
|
||||||
iss.exceptions(ios_base::failbit | ios_base::badbit);
|
iss.exceptions(ios_base::failbit | ios_base::badbit);
|
||||||
|
@ -97,10 +101,11 @@ namespace sgpem
|
||||||
|
|
||||||
// disable exceptions, otherwise peek() will throw them!
|
// disable exceptions, otherwise peek() will throw them!
|
||||||
// how useless!!!
|
// how useless!!!
|
||||||
// iss.exceptions(ios_base::goodbit);
|
iss.exceptions(ios_base::goodbit);
|
||||||
|
|
||||||
|
if (iss.peek() != istringstream::traits_type::eof())
|
||||||
|
throw domain_error(_("incorrect boolean"));
|
||||||
|
|
||||||
// if (iss.peek() != istringstream::traits_type::eof())
|
|
||||||
// throw domain_error(_("incorrect boolean"));
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue