parse: style

This commit is contained in:
Danny Robson 2019-02-02 13:45:34 +11:00
parent 462e1b2a2f
commit ba01794d0b

View File

@ -35,14 +35,14 @@ template <> struct parse_traits<double> { static constexpr auto value = str
template <> struct parse_traits<long double> { static constexpr auto value = strtold; }; template <> struct parse_traits<long double> { static constexpr auto value = strtold; };
//----------------------------------------------------------------------------- ///////////////////////////////////////////////////////////////////////////////
template <typename T> template <typename ValueT>
T ValueT
c_iparse (cruft::view<char const*> &data) c_iparse (cruft::view<char const*> &data)
{ {
auto head = const_cast<char *> (data.begin ()); auto head = const_cast<char *> (data.begin ());
auto tail = head; auto tail = head;
auto val = parse_traits<T>::value (head, &tail, 0); auto val = parse_traits<ValueT>::value (head, &tail, 0);
if (tail == head) if (tail == head)
throw std::invalid_argument ("unable to parse integer"); throw std::invalid_argument ("unable to parse integer");
@ -53,13 +53,13 @@ c_iparse (cruft::view<char const*> &data)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <typename T> template <typename ValueT>
T ValueT
c_fparse (cruft::view<char const*> &data) c_fparse (cruft::view<char const*> &data)
{ {
auto head = const_cast<char *> (data.begin ()); auto head = const_cast<char *> (data.begin ());
auto tail = head; auto tail = head;
auto val = parse_traits<T>::value (head, &tail); auto val = parse_traits<ValueT>::value (head, &tail);
if (tail == head) if (tail == head)
throw std::invalid_argument ("unable to parse float"); throw std::invalid_argument ("unable to parse float");
@ -69,8 +69,6 @@ c_fparse (cruft::view<char const*> &data)
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
/// Specialise cruft::parse for the type KLASS and dispatch the actual parsing /// Specialise cruft::parse for the type KLASS and dispatch the actual parsing
/// to safe template wrappers around the C parsing functions. /// to safe template wrappers around the C parsing functions.
@ -124,6 +122,7 @@ cruft::parse<FINAL> (cruft::view<char const*> &str) { \
return cruft::cast::narrow<FINAL> (res); \ return cruft::cast::narrow<FINAL> (res); \
} }
C_PARSE_WITH_CAST(short, long) C_PARSE_WITH_CAST(short, long)
C_PARSE_WITH_CAST(int, long) C_PARSE_WITH_CAST(int, long)
C_PARSE_WITH_CAST(unsigned short, unsigned long) C_PARSE_WITH_CAST(unsigned short, unsigned long)