validate_zero_buf.hpp
Go to the documentation of this file.
1 #ifndef STAN_IO_VALIDATE_ZERO_BUF_HPP
2 #define STAN_IO_VALIDATE_ZERO_BUF_HPP
3 
4 #include <boost/lexical_cast/bad_lexical_cast.hpp>
5 #include <string>
6 
7 namespace stan {
8  namespace io {
9 
10  /**
11  * Throw an bad-cast exception if the specified buffer contains
12  * a digit other than 0 before an e or E. The buffer argument
13  * must implement <code>size_t size()</code> method and <code>char
14  * operator[](size_t)</code>.
15  *
16  * @tparam B Character buffer type
17  * @throw <code>boost::bad_lexical_cast</code> if the buffer
18  * contains non-zero characters before an exponentiation symbol.
19  */
20  template <typename B>
21  void validate_zero_buf(const B& buf) {
22  for (size_t i = 0; i < buf.size(); ++i) {
23  if (buf[i] == 'e' || buf[i] == 'E')
24  return;
25  if (buf[i] >= '1' && buf[i] <= '9')
26  boost::conversion::detail::throw_bad_cast<std::string, double>();
27  }
28  }
29 
30  }
31 }
32 #endif
void validate_zero_buf(const B &buf)
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154