1  
// Copyright 2022 Peter Dimov
1  
// Copyright 2022 Peter Dimov
2  
// Copyright 2023 Matt Borland
2  
// Copyright 2023 Matt Borland
3  
// Distributed under the Boost Software License, Version 1.0.
3  
// Distributed under the Boost Software License, Version 1.0.
4  
// https://www.boost.org/LICENSE_1_0.txt
4  
// https://www.boost.org/LICENSE_1_0.txt
5  

5  

6  
// https://stackoverflow.com/questions/38060411/visual-studio-2015-wont-suppress-error-c4996
6  
// https://stackoverflow.com/questions/38060411/visual-studio-2015-wont-suppress-error-c4996
7  
#ifndef _SCL_SECURE_NO_WARNINGS
7  
#ifndef _SCL_SECURE_NO_WARNINGS
8  
# define _SCL_SECURE_NO_WARNINGS
8  
# define _SCL_SECURE_NO_WARNINGS
9  
#endif
9  
#endif
10  
#ifndef NO_WARN_MBCS_MFC_DEPRECATION
10  
#ifndef NO_WARN_MBCS_MFC_DEPRECATION
11  
# define NO_WARN_MBCS_MFC_DEPRECATION
11  
# define NO_WARN_MBCS_MFC_DEPRECATION
12  
#endif
12  
#endif
13  

13  

14  
#include <boost/json/detail/charconv/detail/fast_float/fast_float.hpp>
14  
#include <boost/json/detail/charconv/detail/fast_float/fast_float.hpp>
15  
#include <boost/json/detail/charconv/detail/from_chars_float_impl.hpp>
15  
#include <boost/json/detail/charconv/detail/from_chars_float_impl.hpp>
16  
#include <boost/json/detail/charconv/from_chars.hpp>
16  
#include <boost/json/detail/charconv/from_chars.hpp>
17  
#include <system_error>
17  
#include <system_error>
18  
#include <string>
18  
#include <string>
19  
#include <cstdlib>
19  
#include <cstdlib>
20  
#include <cerrno>
20  
#include <cerrno>
21  
#include <cstring>
21  
#include <cstring>
22  

22  

23  
#if defined(__GNUC__) && __GNUC__ < 5
23  
#if defined(__GNUC__) && __GNUC__ < 5
24  
# pragma GCC diagnostic ignored "-Wmissing-field-initializers"
24  
# pragma GCC diagnostic ignored "-Wmissing-field-initializers"
25  
#endif
25  
#endif
26  

26  

27  
std::errc boost::json::detail::charconv::detail::errno_to_errc(int errno_value) noexcept
27  
std::errc boost::json::detail::charconv::detail::errno_to_errc(int errno_value) noexcept
28  
{
28  
{
29  
    switch (errno_value)
29  
    switch (errno_value)
30  
    {
30  
    {
31  
        case EINVAL:
31  
        case EINVAL:
32  
            return std::errc::invalid_argument;
32  
            return std::errc::invalid_argument;
33  
        case ERANGE:
33  
        case ERANGE:
34  
            return std::errc::result_out_of_range;
34  
            return std::errc::result_out_of_range;
35  
        default:
35  
        default:
36  
            return std::errc();
36  
            return std::errc();
37  
    }
37  
    }
38  
}
38  
}
39  

39  

40  
boost::json::detail::charconv::from_chars_result boost::json::detail::charconv::from_chars(const char* first, const char* last, double& value, boost::json::detail::charconv::chars_format fmt) noexcept
40  
boost::json::detail::charconv::from_chars_result boost::json::detail::charconv::from_chars(const char* first, const char* last, double& value, boost::json::detail::charconv::chars_format fmt) noexcept
41  
{
41  
{
42  
    if (fmt != boost::json::detail::charconv::chars_format::hex)
42  
    if (fmt != boost::json::detail::charconv::chars_format::hex)
43  
    {
43  
    {
44  
        return boost::json::detail::charconv::detail::fast_float::from_chars(first, last, value, fmt);
44  
        return boost::json::detail::charconv::detail::fast_float::from_chars(first, last, value, fmt);
45  
    }
45  
    }
46  
    return boost::json::detail::charconv::detail::from_chars_float_impl(first, last, value, fmt);
46  
    return boost::json::detail::charconv::detail::from_chars_float_impl(first, last, value, fmt);
47  
}
47  
}