- Begin writing the ADD command. Im assuming you all like what Im doing...

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@759 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
elvez 2006-07-13 15:07:15 +00:00
parent 456cef0fd3
commit 751ecf6415
3 changed files with 186 additions and 7 deletions

View file

@ -19,7 +19,7 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "string_utils.hh"
#include "gettext.h"
#include <sstream>
using namespace std;
@ -77,7 +77,7 @@ T
string_to(const ustring& str) throw(domain_error)
{
if(tokenize(str).size() != 1)
throw domain_error("too few or too many tokens");
throw domain_error(_("too few or too many tokens"));
istringstream iss(str);
@ -99,7 +99,39 @@ string_to(const ustring& str) throw(domain_error)
iss.exceptions(ios_base::goodbit);
if(iss.peek() != istringstream::traits_type::eof())
throw domain_error("incorrect number format");
throw domain_error(_("incorrect number format"));
return value;
}
template <>
bool
string_to<bool>(const Glib::ustring& str) throw(domain_error)
{
if(tokenize(str).size() != 1)
throw domain_error(_("too few or too many tokens"));
istringstream iss(str);
iss.exceptions(ios_base::failbit | ios_base::badbit);
bool value;
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;
}
@ -197,5 +229,5 @@ tokenize(const ustring& str)
template int string_to<int>(const Glib::ustring&);
template float string_to<float>(const Glib::ustring&);
template bool string_to<bool>(const Glib::ustring&);
}