From c6f483d077abc7ff5c6b1a52fca35583e5980e0f Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 2 Aug 2016 18:50:35 +1000 Subject: [PATCH] ascii: add to_integer from ascii to numeric --- ascii.hpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ascii.hpp b/ascii.hpp index b951ad93..b49cff5b 100644 --- a/ascii.hpp +++ b/ascii.hpp @@ -17,6 +17,11 @@ #ifndef __CRUFT_UTIL_ASCII_HPP #define __CRUFT_UTIL_ASCII_HPP +#include "./annotation.hpp" + +#include +#include + 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