ascii: add to_integer from ascii to numeric

This commit is contained in:
Danny Robson 2016-08-02 18:50:35 +10:00
parent 3a0f20e68b
commit c6f483d077

View File

@ -17,6 +17,11 @@
#ifndef __CRUFT_UTIL_ASCII_HPP
#define __CRUFT_UTIL_ASCII_HPP
#include "./annotation.hpp"
#include <cstdint>
#include <stdexcept>
namespace util { namespace ascii {
///////////////////////////////////////////////////////////////////////////
constexpr inline
@ -26,6 +31,16 @@ namespace util { namespace ascii {
return c >= '0' && c <= '9';
}
//-------------------------------------------------------------------------
constexpr inline
uint8_t
to_integer (char c)
{
return likely (is_digit (c)) ?
c - '0'
: throw std::invalid_argument ("character is not a digit");
}
//-------------------------------------------------------------------------
constexpr inline