From 672bd3b8728ea256989b65d905eebf44e5fa21da Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Wed, 11 Jan 2023 11:26:06 -0800 Subject: [PATCH] Refactor detail namespace --- include/boost/charconv/from_chars.hpp | 31 ---------------- src/from_chars.cpp | 52 +++++++++++++++++++-------- 2 files changed, 38 insertions(+), 45 deletions(-) diff --git a/include/boost/charconv/from_chars.hpp b/include/boost/charconv/from_chars.hpp index 781ae1d..1d68a8f 100644 --- a/include/boost/charconv/from_chars.hpp +++ b/include/boost/charconv/from_chars.hpp @@ -37,37 +37,6 @@ struct from_chars_result } }; -namespace detail { - -static constexpr std::array uchar_values = - {{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 255, 255, 255, 255, 255, 255, - 255, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, - 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 255, 255, 255, 255, 255, - 255, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, - 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}}; - -// Convert characters for 0-9, A-Z, a-z to 0-35. Anything else is 255 -inline unsigned char digit_from_char(char val) noexcept -{ - return uchar_values[static_cast(val)]; -} - -template ::value, bool>::type = true> -boost::charconv::from_chars_result from_chars(const char* first, const char* last, Integer& value, int base) noexcept; - -} // Namespace detail - BOOST_CHARCONV_DECL from_chars_result from_chars(const char* first, const char* last, char& value, int base = 10) noexcept; BOOST_CHARCONV_DECL from_chars_result from_chars(const char* first, const char* last, unsigned char& value, int base = 10) noexcept; BOOST_CHARCONV_DECL from_chars_result from_chars(const char* first, const char* last, short& value, int base = 10) noexcept; diff --git a/src/from_chars.cpp b/src/from_chars.cpp index e23bea8..9649e20 100644 --- a/src/from_chars.cpp +++ b/src/from_chars.cpp @@ -14,6 +14,30 @@ namespace boost { namespace charconv { namespace detail { +static constexpr std::array uchar_values = + {{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 255, 255, 255, 255, 255, 255, + 255, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 255, 255, 255, 255, 255, + 255, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}}; + +// Convert characters for 0-9, A-Z, a-z to 0-35. Anything else is 255 +inline unsigned char digit_from_char(char val) noexcept +{ + return uchar_values[static_cast(val)]; +} + template ::value, bool>::type = true> inline Integer apply_sign(Integer val) noexcept { @@ -26,10 +50,8 @@ inline Integer apply_sign(Integer val) noexcept return val; } -}}} // Namespaces - -template ::value, bool>::type> -boost::charconv::from_chars_result boost::charconv::detail::from_chars(const char* first, const char* last, Integer& value, int base) noexcept +template ::value, bool>::type = true> +boost::charconv::from_chars_result from_chars_impl(const char* first, const char* last, Integer& value, int base) noexcept { using Unsigned_Integer = typename std::make_unsigned::type; Unsigned_Integer result = 0; @@ -126,52 +148,54 @@ boost::charconv::from_chars_result boost::charconv::detail::from_chars(const cha return {next, 0}; } +}}} // Namespace boost::charconv::detail + boost::charconv::from_chars_result boost::charconv::from_chars(const char* first, const char* last, char& value, int base) noexcept { - return boost::charconv::detail::from_chars(first, last, value, base); + return boost::charconv::detail::from_chars_impl(first, last, value, base); } boost::charconv::from_chars_result boost::charconv::from_chars(const char* first, const char* last, unsigned char& value, int base) noexcept { - return boost::charconv::detail::from_chars(first, last, value, base); + return boost::charconv::detail::from_chars_impl(first, last, value, base); } boost::charconv::from_chars_result boost::charconv::from_chars(const char* first, const char* last, short& value, int base) noexcept { - return boost::charconv::detail::from_chars(first, last, value, base); + return boost::charconv::detail::from_chars_impl(first, last, value, base); } boost::charconv::from_chars_result boost::charconv::from_chars(const char* first, const char* last, unsigned short& value, int base) noexcept { - return boost::charconv::detail::from_chars(first, last, value, base); + return boost::charconv::detail::from_chars_impl(first, last, value, base); } boost::charconv::from_chars_result boost::charconv::from_chars(const char* first, const char* last, int& value, int base) noexcept { - return boost::charconv::detail::from_chars(first, last, value, base); + return boost::charconv::detail::from_chars_impl(first, last, value, base); } boost::charconv::from_chars_result boost::charconv::from_chars(const char* first, const char* last, unsigned int& value, int base) noexcept { - return boost::charconv::detail::from_chars(first, last, value, base); + return boost::charconv::detail::from_chars_impl(first, last, value, base); } boost::charconv::from_chars_result boost::charconv::from_chars(const char* first, const char* last, long& value, int base) noexcept { - return boost::charconv::detail::from_chars(first, last, value, base); + return boost::charconv::detail::from_chars_impl(first, last, value, base); } boost::charconv::from_chars_result boost::charconv::from_chars(const char* first, const char* last, unsigned long& value, int base) noexcept { - return boost::charconv::detail::from_chars(first, last, value, base); + return boost::charconv::detail::from_chars_impl(first, last, value, base); } boost::charconv::from_chars_result boost::charconv::from_chars(const char* first, const char* last, long long& value, int base) noexcept { - return boost::charconv::detail::from_chars(first, last, value, base); + return boost::charconv::detail::from_chars_impl(first, last, value, base); } boost::charconv::from_chars_result boost::charconv::from_chars(const char* first, const char* last, unsigned long long& value, int base) noexcept { - return boost::charconv::detail::from_chars(first, last, value, base); + return boost::charconv::detail::from_chars_impl(first, last, value, base); }