Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r73311 - sandbox/coerce/libs/coerce/example
From: vexocide_at_[hidden]
Date: 2011-07-23 09:01:02


Author: vexocide
Date: 2011-07-23 09:01:02 EDT (Sat, 23 Jul 2011)
New Revision: 73311
URL: http://svn.boost.org/trac/boost/changeset/73311

Log:
Fixed and added error checking to the backend example
Text files modified:
   sandbox/coerce/libs/coerce/example/backend.cpp | 21 ++++++++++++++++-----
   1 files changed, 16 insertions(+), 5 deletions(-)

Modified: sandbox/coerce/libs/coerce/example/backend.cpp
==============================================================================
--- sandbox/coerce/libs/coerce/example/backend.cpp (original)
+++ sandbox/coerce/libs/coerce/example/backend.cpp 2011-07-23 09:01:02 EDT (Sat, 23 Jul 2011)
@@ -7,8 +7,8 @@
 #define BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
 
 #include <boost/coerce.hpp>
-#include <boost/spirit/include/support_unused.hpp>
 
+#include <cctype> // for std::isspace
 #include <cerrno> // for errno
 #include <cstdio> // for std::strtol
 #include <iostream>
@@ -16,17 +16,28 @@
 struct strtol {
     template <typename Target, typename Source, typename Tag>
     static inline bool
- call(Target & target, Source const & source) {
- target = std::strtol(source, NULL, 10);
+ call(Target & target, Source const & source, Tag const &) {
+ char *end;
+
+ if (std::isspace(*source)) {
+ return false;
+ }
+
+ errno = 0;
+ target = std::strtol(source, &end, 10);
+
+ if (errno != 0 || *end != 0 || source == end) {
+ return false;
+ }
 
- return (errno != EINVAL);
+ return true;
     }
 };
 
 namespace boost { namespace coerce { namespace traits {
 
     template <std::size_t N>
- struct as<long int, char [N], spirit::unused_type>
+ struct as<long int, char [N], tag::none>
         : strtol { };
 
 } } } // namespace boost::coerce::traits


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk