mirror of
https://github.com/boostorg/charconv.git
synced 2026-02-02 08:42:13 +00:00
Merge pull request #144 from cppalliance/space
This commit is contained in:
@@ -99,7 +99,7 @@ BOOST_CXX14_CONSTEXPR from_chars_result from_chars_integer_impl(const char* firs
|
||||
is_negative = true;
|
||||
++next;
|
||||
}
|
||||
else if (*next == '+')
|
||||
else if (*next == '+' || *next == ' ')
|
||||
{
|
||||
return {next, std::errc::invalid_argument};
|
||||
}
|
||||
@@ -126,7 +126,7 @@ BOOST_CXX14_CONSTEXPR from_chars_result from_chars_integer_impl(const char* firs
|
||||
}
|
||||
else
|
||||
{
|
||||
if (next != last && (*next == '-' || *next == '+'))
|
||||
if (next != last && (*next == '-' || *next == '+' || *next == ' '))
|
||||
{
|
||||
return {first, std::errc::invalid_argument};
|
||||
}
|
||||
|
||||
@@ -183,6 +183,18 @@ void invalid_argument_test()
|
||||
auto r7 = boost::charconv::from_chars(buffer7, buffer7 + std::strlen(buffer7), v7);
|
||||
BOOST_TEST(r7.ec == std::errc::invalid_argument);
|
||||
BOOST_TEST_EQ(v7, static_cast<T>(3));
|
||||
|
||||
const char* buffer8 = " 12345";
|
||||
T v8 = 3;
|
||||
auto r8 = boost::charconv::from_chars(buffer8, buffer8 + std::strlen(buffer8), v8);
|
||||
BOOST_TEST(r8.ec == std::errc::invalid_argument);
|
||||
BOOST_TEST_EQ(v8, static_cast<T>(3));
|
||||
|
||||
const char* buffer9 = "123 45";
|
||||
T v9 = 3;
|
||||
auto r9 = boost::charconv::from_chars(buffer9, buffer9 + std::strlen(buffer9), v9);
|
||||
BOOST_TEST(r9);
|
||||
BOOST_TEST_EQ(v9, static_cast<T>(123));
|
||||
}
|
||||
|
||||
// No overflows, negative numbers, locales, etc.
|
||||
|
||||
@@ -74,7 +74,7 @@ void spot_check_inf(const std::string& buffer, boost::charconv::chars_format fmt
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void spot_check_bad_non_finite(const std::string& buffer, boost::charconv::chars_format fmt)
|
||||
void spot_check_invalid_argument(const std::string& buffer, boost::charconv::chars_format fmt)
|
||||
{
|
||||
T v = static_cast<T>(5.0L);
|
||||
auto r = boost::charconv::from_chars(buffer.c_str(), buffer.c_str() + buffer.size(), v, fmt);
|
||||
@@ -1881,9 +1881,16 @@ int main()
|
||||
spot_check_nan<double>("-nan(ind)", fmt);
|
||||
spot_check_nan<long double>("-nan(ind)", fmt);
|
||||
|
||||
spot_check_bad_non_finite<float>("na7", fmt);
|
||||
spot_check_bad_non_finite<float>("na", fmt);
|
||||
spot_check_bad_non_finite<float>("in", fmt);
|
||||
spot_check_invalid_argument<float>("na7", fmt);
|
||||
spot_check_invalid_argument<float>("na", fmt);
|
||||
spot_check_invalid_argument<float>("in", fmt);
|
||||
|
||||
spot_check_invalid_argument<float>(" 1.23", fmt);
|
||||
spot_check_invalid_argument<float>(" 1.23", fmt);
|
||||
spot_check_invalid_argument<double>(" 1.23", fmt);
|
||||
spot_check_invalid_argument<double>(" 1.23", fmt);
|
||||
spot_check_invalid_argument<long double>(" 1.23", fmt);
|
||||
spot_check_invalid_argument<long double>(" 1.23", fmt);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
|
||||
Reference in New Issue
Block a user