diff --git a/src/backend/string_utils.cc b/src/backend/string_utils.cc index 876f235..4d56225 100644 --- a/src/backend/string_utils.cc +++ b/src/backend/string_utils.cc @@ -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; }