json/include/nlohmann/detail/input/numerizer.hpp

49 lines
1.0 KiB
C++
Raw Normal View History

2021-12-07 03:51:27 +03:00
#pragma once
#include <cstdint> // uint64_t, int64_t
2021-12-07 03:51:27 +03:00
#include <cstdlib> // strtof, strtod, strtold, strtoll, strtoull
#include <nlohmann/detail/macro_scope.hpp>
2021-12-07 03:51:27 +03:00
namespace nlohmann
{
namespace detail
{
2021-12-07 03:51:27 +03:00
struct numerizer
{
JSON_HEDLEY_NON_NULL(2)
static void strtof(float& f, const char* str, char** endptr) noexcept
{
f = std::strtof(str, endptr);
}
JSON_HEDLEY_NON_NULL(2)
static void strtof(double& f, const char* str, char** endptr) noexcept
{
f = std::strtod(str, endptr);
}
JSON_HEDLEY_NON_NULL(2)
static void strtof(long double& f, const char* str, char** endptr) noexcept
{
f = std::strtold(str, endptr);
}
2021-12-07 03:51:27 +03:00
JSON_HEDLEY_NON_NULL(2)
static uint64_t strtoull(const char* str, char** endptr, int base)
2021-12-07 03:51:27 +03:00
{
return std::strtoull(str, endptr, base);
}
2021-12-07 03:51:27 +03:00
JSON_HEDLEY_NON_NULL(2)
static int64_t strtoll(const char* str, char** endptr, int base)
2021-12-07 03:51:27 +03:00
{
return std::strtoll(str, endptr, base);
}
};
} // namespace detail
} // namespace nlohmann