diff --git a/include/etl/to_arithmetic.h b/include/etl/to_arithmetic.h index 4dc53a6f0..da0f50524 100644 --- a/include/etl/to_arithmetic.h +++ b/include/etl/to_arithmetic.h @@ -164,7 +164,7 @@ namespace etl } //******************************************* - /// + /// Assignment from a value. //******************************************* ETL_CONSTEXPR14 to_arithmetic_result& operator =(value_type value_) @@ -175,7 +175,7 @@ namespace etl } //******************************************* - /// + /// Assignment from an unexpected_type. //******************************************* ETL_CONSTEXPR14 to_arithmetic_result& operator =(unexpected_type status_) @@ -300,7 +300,8 @@ namespace etl } //*************************************************************************** - /// + /// Checks to see if the text starts with a '+' or '-' prefix, and modifies the view to remove it. + /// Returns true if the text has a '-' prefix. //*************************************************************************** template ETL_NODISCARD @@ -326,7 +327,7 @@ namespace etl } //*************************************************************************** - /// + /// Checks to see if the radix is valid. //*************************************************************************** ETL_NODISCARD inline @@ -775,9 +776,9 @@ namespace etl ETL_NODISCARD ETL_CONSTEXPR14 typename etl::enable_if::value, etl::to_arithmetic_result >::type - to_arithmetic(const etl::basic_string_view& view, const etl::basic_format_spec >& spec) + to_arithmetic(const etl::basic_string_view& view, const typename etl::private_basic_format_spec::base_spec& spec) { - return etl::to_arithmetic(view, spec.get_base()); + return etl::to_arithmetic(view, spec.base); } //*************************************************************************** @@ -816,42 +817,6 @@ namespace etl return etl::to_arithmetic(etl::basic_string_view(cp, length), spec.base); } - //*************************************************************************** - /// Text to integral from pointer and radix value type. - //*************************************************************************** - template - ETL_NODISCARD - ETL_CONSTEXPR14 - typename etl::enable_if::value, etl::to_arithmetic_result >::type - to_arithmetic(const TChar* cp, const etl::radix::value_type radix) - { - return etl::to_arithmetic(etl::basic_string_view(cp, etl::strlen(cp), radix)); - } - - //*************************************************************************** - /// Text to integral from pointer and default decimal radix. - //*************************************************************************** - template - ETL_NODISCARD - ETL_CONSTEXPR14 - typename etl::enable_if::value, etl::to_arithmetic_result >::type - to_arithmetic(const TChar* cp) - { - return etl::to_arithmetic(etl::basic_string_view(cp, etl::strlen(cp)), etl::radix::decimal);; - } - - //*************************************************************************** - /// Text to integral from pointer and radix format spec. - //*************************************************************************** - template - ETL_NODISCARD - ETL_CONSTEXPR14 - typename etl::enable_if::value, etl::to_arithmetic_result >::type - to_arithmetic(const TChar* cp, const typename etl::private_basic_format_spec::base_spec& spec) - { - return etl::to_arithmetic(etl::basic_string_view(cp, etl::strlen(cp)), spec.base);; - } - //*************************************************************************** /// Text to integral from string and radix value type. //*************************************************************************** @@ -869,8 +834,8 @@ namespace etl //*************************************************************************** template ETL_NODISCARD - ETL_CONSTEXPR14 - typename etl::enable_if::value, etl::to_arithmetic_result >::type + ETL_CONSTEXPR14 + typename etl::enable_if::value, etl::to_arithmetic_result >::type to_arithmetic(const etl::ibasic_string& str) { return etl::to_arithmetic(etl::basic_string_view(str), etl::radix::decimal);; @@ -883,7 +848,7 @@ namespace etl ETL_NODISCARD ETL_CONSTEXPR14 typename etl::enable_if::value, etl::to_arithmetic_result >::type - to_arithmetic(const etl::ibasic_string& str, const etl::basic_format_spec >& spec) + to_arithmetic(const etl::ibasic_string& str, const typename etl::private_basic_format_spec::base_spec& spec) { return etl::to_arithmetic(etl::basic_string_view(str), spec);; } diff --git a/test/test_to_arithmetic.cpp b/test/test_to_arithmetic.cpp index a5f4f19a3..2084ea86a 100644 --- a/test/test_to_arithmetic.cpp +++ b/test/test_to_arithmetic.cpp @@ -1004,6 +1004,29 @@ namespace CHECK_EQUAL(etl::to_arithmetic_status::Overflow, etl::to_arithmetic(text.c_str(), text.size()).error()); } + //************************************************************************* + TEST(test_all_api_variants) + { + const Text text(STR("83")); + + using ETLText = etl::string<2>; + + // Default radix + CHECK_EQUAL(int(83), int(etl::to_arithmetic(etl::string_view(text.c_str(), text.size())).value())); + CHECK_EQUAL(int(83), int(etl::to_arithmetic(text.c_str(), text.size()).value())); + CHECK_EQUAL(int(83), int(etl::to_arithmetic(ETLText(text.c_str(), text.size())).value())); + + // Format spec radix + CHECK_EQUAL(int(83), int(etl::to_arithmetic(etl::string_view(text.c_str(), text.size()), etl::dec).value())); + CHECK_EQUAL(int(83), int(etl::to_arithmetic(text.c_str(), text.size(), etl::dec).value())); + CHECK_EQUAL(int(83), int(etl::to_arithmetic(ETLText(text.c_str(), text.size()), etl::dec).value())); + + // Numeric radix + CHECK_EQUAL(int(83), int(etl::to_arithmetic(etl::string_view(text.c_str(), text.size()), etl::radix::decimal).value())); + CHECK_EQUAL(int(83), int(etl::to_arithmetic(text.c_str(), text.size(), etl::radix::decimal).value())); + CHECK_EQUAL(int(83), int(etl::to_arithmetic(ETLText(text.c_str(), text.size()), etl::radix::decimal).value())); + } + //************************************************************************* TEST(test_constexpr_integral) {